Skip to content
Snippets Groups Projects
Commit fac4308b authored by Hans William Forbrigd's avatar Hans William Forbrigd
Browse files

Merge branch 'william_feature_structure' into 'main'

figure out assignments

See merge request mattiaae/idatt2900-072!3
parents 50e27d1c 728b87c6
No related branches found
No related tags found
No related merge requests found
...@@ -5,17 +5,17 @@ from typing import Optional ...@@ -5,17 +5,17 @@ from typing import Optional
import typer import typer
from bbcli import __app_name__, __version__ from bbcli import __app_name__, __version__, endpoints
app = typer.Typer() app = typer.Typer()
app.add_typer(endpoints.app, name='endpoints', help='Call the endpoints')
def _version_callback(value: bool) -> None: def _version_callback(value: bool) -> None:
if value: if value:
typer.echo(f"{__app_name__} v{__version__}") typer.echo(f"{__app_name__} v{__version__}")
raise typer.Exit() raise typer.Exit()
@app.callback() @app.callback()
def main( def main(
version: Optional[bool] = typer.Option( version: Optional[bool] = typer.Option(
...@@ -27,4 +27,4 @@ def main( ...@@ -27,4 +27,4 @@ def main(
is_eager=True, is_eager=True,
) )
) -> None: ) -> None:
return return
\ No newline at end of file
...@@ -9,17 +9,19 @@ from typing import Optional ...@@ -9,17 +9,19 @@ from typing import Optional
app = typer.Typer() app = typer.Typer()
cookies = {'BbRouter': 'expires:1645202601,id:2480855EED2012DA032F19DEE1610883,signature:81a13d5bdf4946a82a632a9035c0f35811f217671da872677b1d1c32e7a3c339,site:f4fe20be-98b0-4ecd-9039-d18ce2989292,timeout:10800,user:15bd75dd85af4f56b31283276eb8da7c,v:2,xsrf:1bea7fee-fa91-4197-991f-1d266fd1ceee'} cookies = {'BbRouter' : 'expires:1645629198,id:B568F329FB52485B02F9D45307C27083,signature:e13c22f908162232cf18e5f4bbe698d5f7c904edca932f6a27263b374f5e7ac5,site:f4fe20be-98b0-4ecd-9039-d18ce2989292,timeout:10800,user:15bd75dd85af4f56b31283276eb8da7c,v:2,xsrf:03f9f512-620d-4f11-b84f-65f1daba0cfc'}
base_url = 'https://ntnu.blackboard.com/learn/api/public/v1/' base_url = 'https://ntnu.blackboard.com/learn/api/public/v1/'
@app.command() @app.command(name='get-user')
def getuser(user_name: str = typer.Argument('hanswf', help='Name of the user'))-> None: def get_user(user_name: str = typer.Argument('', help='Name of the user'))-> None:
''' '''
Get the user. Get the user
Specify the user_name as an option, or else it will use the default user_name Specify the user_name as an option, or else it will use the default user_name
''' '''
url = base_url + 'users?userName=%s' % user_name if user_name == '':
user_name = typer.prompt("What is your user name?")
url = f'{base_url}users?userName={user_name}'
x = requests.get( x = requests.get(
url, url,
cookies=cookies cookies=cookies
...@@ -30,8 +32,11 @@ def getuser(user_name: str = typer.Argument('hanswf', help='Name of the user'))- ...@@ -30,8 +32,11 @@ def getuser(user_name: str = typer.Argument('hanswf', help='Name of the user'))-
print(pprint.pprint(data)) print(pprint.pprint(data))
@app.command() @app.command(name='get-course')
def getcourse(course_id: str = 'IDATT2900'): def get_course(course_id: str = 'IDATT2900'):
'''
Get the course
'''
url = base_url + 'courses?courseId=%s' % course_id url = base_url + 'courses?courseId=%s' % course_id
x = requests.get( x = requests.get(
url, url,
...@@ -40,13 +45,59 @@ def getcourse(course_id: str = 'IDATT2900'): ...@@ -40,13 +45,59 @@ def getcourse(course_id: str = 'IDATT2900'):
print(pprint.pprint(data)) print(pprint.pprint(data))
@app.command() @app.command(name='get-course-contents')
def getcoursecontents(course_id: str = '_27251_1'): def get_course_contents(course_id: str = '_27251_1'):
'''
Get the course contents
'''
url = f'{base_url}courses/{course_id}/contents' url = f'{base_url}courses/{course_id}/contents'
x = requests.get(url, cookies=cookies) x = requests.get(url, cookies=cookies)
data = x.json() data = x.json()
print(pprint.pprint(data)) print(pprint.pprint(data))
def get_children(d, url,acc, count: int = 0):
#count = count + 1
#print(f'kommer hit: {count}')
key = 'hasChildren'
if key not in d or d[key] == False:
print('nei')
return acc
else:
print('ja')
id = d['id']
url = f'{url}/{id}/children'
print(url)
response = requests.get(url, cookies = cookies)
child = response.json()['results']
#get_children(child, url, acc+child, count)
return child
def get_children(d, url):
key = 'hasChildren'
while key in d and d[key] == True:
id = d['id']
url = f'{url}/{id}/children'
print()
print(url)
print()
response = requests.get(url, cookies=cookies)
child = response.json()['results']
return child
if __name__ == "__main__":
app() @app.command(name='get-assignments')
\ No newline at end of file def get_assignments(course_id: str = typer.Argument('_27251_1', help='The course id')):
'''
Get the assignments
'''
url = f'{base_url}courses/{course_id}/contents'
x = requests.get(url, cookies=cookies)
data = x.json()['results']
#res = get_children(data[2], url, [])
res = get_children(data[2], url)
print(pprint.pprint(res))
#print(pprint.pprint(data))
#for d in data:
#print()
#print(get_children(d, url))
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