Skip to content
Snippets Groups Projects
Commit 54a14df6 authored by williamforbrigd's avatar williamforbrigd
Browse files

stuff

parent 5b2412c9
No related branches found
No related tags found
No related merge requests found
Showing with 178 additions and 0 deletions
# IDATT2900-072
useful stuff
to run the tests:
python -m pytest tests
python -m bbcli --version
\ No newline at end of file
"""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
"""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
File added
File added
File added
File added
File moved
"""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
File moved
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
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
typer==0.3.2
colorama==0.4.4
shellingham==1.4.0
pytest==6.2.4
\ No newline at end of file
"""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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment