diff --git a/README.md b/README.md index d84ef5d3b573d26571fcaab348a821f1e5807860..b92427e5492a505bcd8a8d83b331cbee1230dd2c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # IDATT2900-072 +useful stuff +to run the tests: +python -m pytest tests + +python -m bbcli --version \ No newline at end of file diff --git a/bbcli/__init__.py b/bbcli/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..2ee7022491f8ff854ce033d651d3d32623e69b96 --- /dev/null +++ b/bbcli/__init__.py @@ -0,0 +1,23 @@ +"""Top-level package for RP To-Do.""" +# rptodo/__init__.py + +__app_name__ = "bbcli" +__version__ = "0.1.0" + +( + SUCCESS, + DIR_ERROR, + FILE_ERROR, + DB_READ_ERROR, + DB_WRITE_ERROR, + JSON_ERROR, + ID_ERROR, +) = range(7) + +ERRORS = { + DIR_ERROR: "config directory error", + FILE_ERROR: "config file error", + DB_READ_ERROR: "database read error", + DB_WRITE_ERROR: "database write error", + ID_ERROR: "to-do id error", +} \ No newline at end of file diff --git a/bbcli/__main__.py b/bbcli/__main__.py new file mode 100644 index 0000000000000000000000000000000000000000..59b707a8fe5bf28c406d17e4bae8ae3fdb656ea8 --- /dev/null +++ b/bbcli/__main__.py @@ -0,0 +1,10 @@ +"""RP To-Do entry point script.""" +# rptodo/__main__.py + +from bbcli import cli, __app_name__ + +def main(): + cli.app(prog_name=__app_name__) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/bbcli/__pycache__/__init__.cpython-38.pyc b/bbcli/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f119ac4d8542a41c1f6fd604b26cf288fbb5b733 Binary files /dev/null and b/bbcli/__pycache__/__init__.cpython-38.pyc differ diff --git a/bbcli/__pycache__/__main__.cpython-38.pyc b/bbcli/__pycache__/__main__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..01e5a116ba5ae56cfa8bece39128f56b01822c72 Binary files /dev/null and b/bbcli/__pycache__/__main__.cpython-38.pyc differ diff --git a/bbcli/__pycache__/cli.cpython-38.pyc b/bbcli/__pycache__/cli.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..14d5dcf4b87a2cf4d59492ebeec9ad3ef14d8206 Binary files /dev/null and b/bbcli/__pycache__/cli.cpython-38.pyc differ diff --git a/bbcli/__pycache__/string_builder.cpython-38.pyc b/bbcli/__pycache__/string_builder.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a0ac78f407ebd5270e5a2ef7af6f9fc8197c94eb Binary files /dev/null and b/bbcli/__pycache__/string_builder.cpython-38.pyc differ diff --git a/bblib/bblib.py b/bbcli/bblib.py similarity index 100% rename from bblib/bblib.py rename to bbcli/bblib.py diff --git a/bbcli/cli.py b/bbcli/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..0389e531023a3e30efd146ed84868c2342f1e80b --- /dev/null +++ b/bbcli/cli.py @@ -0,0 +1,28 @@ +"""This module provides the RP To-Do CLI.""" +# rptodo/cli.py + +from typing import Optional + +import typer + +from bbcli import __app_name__, __version__ + +app = typer.Typer() + +def _version_callback(value: bool) -> None: + if value: + typer.echo(f"{__app_name__} v{__version__}") + raise typer.Exit() + +@app.callback() +def main( + version: Optional[bool] = typer.Option( + None, + "--version", + "-v", + help="Show the application's version and exit.", + callback=_version_callback, + is_eager=True, + ) +) -> None: + return \ No newline at end of file diff --git a/bblib/config.py b/bbcli/config.py similarity index 100% rename from bblib/config.py rename to bbcli/config.py diff --git a/bbcli/endpoints.py b/bbcli/endpoints.py new file mode 100644 index 0000000000000000000000000000000000000000..64f06caa80416954ef472c77e5c37e9df41625c1 --- /dev/null +++ b/bbcli/endpoints.py @@ -0,0 +1,61 @@ +import requests +#from requests.auth import HTTPBasicAuth +import json +import pprint +import typer +from string_builder import StringBuilder + +app = typer.Typer() + + +cookies = {'BbRouter': 'expires:1645028532,id:FB0C2EC2C0F7E65CBF8DA06E10933C29,signature:e283fbd97b70959a733dd7a18e23db8a5420fe305678f468b53a29dc1c9fc01a,site:f4fe20be-98b0-4ecd-9039-d18ce2989292,timeout:10800,user:15bd75dd85af4f56b31283276eb8da7c,v:2,xsrf:6d7d4b40-4fb4-40b9-8d4c-800162d2137a'} +base_str = 'https://ntnu.blackboard.com/learn/api/public/v1/' + + +@app.command() +def getuser(user_name: str): + ''' + url = StringBuilder() + url.append(base_str) + url.append('users?userName=') + url.append(user_name) + print(url) + ''' + url = 'https://ntnu.blackboard.com/learn/api/public/v1/users?userName=%s' % user_name + x = requests.get( + url, + cookies=cookies + ) + + data = x.json() + # print(data) + print(pprint.pprint(data)) + + +@app.command() +def getcourse(course_id: str): + url = 'https://ntnu.blackboard.com/learn/api/public/v1/courses?courseId=%s' % course_id + x = requests.get( + url, + cookies=cookies) + data = x.json() + print(pprint.pprint(data)) + + +@app.command() +def getcoursecontents(): + id: str = '_27251_1' + url = 'https://ntnu.blackboard.com/learn/api/public/v1/courses/%s/contents' % id + x = requests.get(url, cookies=cookies) + data = x.json() + print(pprint.pprint(data)) + + +if __name__ == "__main__": + ''' + sb = StringBuilder() + sb.append("Hello") + sb.append("World") + print(sb) + ''' + app() \ No newline at end of file diff --git a/bbcli/string_builder.py b/bbcli/string_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..d4f98271b67f1a26500447d26643b80aa7d30c55 --- /dev/null +++ b/bbcli/string_builder.py @@ -0,0 +1,14 @@ +from io import StringIO + + +class StringBuilder: + _file_str = None + + def __init__(self): + self._file_str = StringIO() + + def append(self, str): + self._file_str.write(str) + + def __str__(self): + return self._file_str.getvalue() \ No newline at end of file diff --git a/bblib/__init__.py b/bblib/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/bblib/__main__.py b/bblib/__main__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/bblib/cli.py b/bblib/cli.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/requirements.txt b/requirements.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..34c7acc74d66af61fb8af62417f8a6c2f4b872f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,4 @@ +typer==0.3.2 +colorama==0.4.4 +shellingham==1.4.0 +pytest==6.2.4 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a3ebc333fcbf625e61d15fc25730140afa8126d7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,23 @@ +"""Top-level package for RP To-Do.""" +# rptodo/__init__.py + +__app_name__ = "rptodo" +__version__ = "0.1.0" + +( + SUCCESS, + DIR_ERROR, + FILE_ERROR, + DB_READ_ERROR, + DB_WRITE_ERROR, + JSON_ERROR, + ID_ERROR, +) = range(7) + +ERRORS = { + DIR_ERROR: "config directory error", + FILE_ERROR: "config file error", + DB_READ_ERROR: "database read error", + DB_WRITE_ERROR: "database write error", + ID_ERROR: "to-do id error", +} \ No newline at end of file diff --git a/tests/test_bbcli.py b/tests/test_bbcli.py new file mode 100644 index 0000000000000000000000000000000000000000..d5888d555791862a8054e02ac44ac869c92de2a0 --- /dev/null +++ b/tests/test_bbcli.py @@ -0,0 +1,10 @@ +from typer.testing import CliRunner + +from bbcli import __app_name__, __version__, cli + +runner = CliRunner() + +def test_version(): + result = runner.invoke(cli.app, ["--version"]) + assert result.exit_code == 0 + assert f"{__app_name__} v{__version__}\n" in result.stdout \ No newline at end of file diff --git a/tests/test_bblib.py b/tests/test_bblib.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000