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

get all the assignments for folder

parent 2ee52373
No related branches found
No related tags found
No related merge requests found
class Node(object): class Node(object):
def __init__(self, data, children=None): def __init__(self, data, children=None):
self.data = data self.data = data
self.children = [] self.children = children
if children is not None: if children is not None:
for child in children: for child in children:
self.add_child(child) self.add_child(child)
def __repr__(self):
return self.name def add_child(self, node):
def add_child(self, node): assert isinstance(node, Node)
assert isinstance(node, Node) self.chilren.append(node)
self.children.append(node)
\ No newline at end of file # class Node(object):
# def __init__(self, data, children=None):
# self.data = data
# self.children = []
# if children is not None:
# for child in children:
# self.add_child(child)
# def __repr__(self):
# return self.name
# def add_child(self, node):
# assert isinstance(node, Node)
# self.children.append(node)
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
__app_name__ = "bbcli" __app_name__ = "bbcli"
__version__ = "0.1.0" __version__ = "0.1.0"
from .endpoints import * from .endpoints import *
from .Node import * from .Node import Node
( (
SUCCESS, SUCCESS,
......
"""RP To-Do entry point script.""" """RP To-Do entry point script."""
# rptodo/__main__.py # rptodo/__main__.py
from dotenv import load_dotenv
from bbcli import cli, __app_name__ from bbcli import cli, __app_name__
def main(): def main():
......
...@@ -7,10 +7,9 @@ import typer ...@@ -7,10 +7,9 @@ import typer
import click import click
from typing import Optional from typing import Optional
from dotenv import load_dotenv from dotenv import load_dotenv
from bbcli.Node import Node
import os import os
from bbcli import Node
app = typer.Typer() app = typer.Typer()
...@@ -91,7 +90,7 @@ def get_course_contents(course_id: str = '_27251_1'): ...@@ -91,7 +90,7 @@ def get_course_contents(course_id: str = '_27251_1'):
# for d in data: # for d in data:
# typer.echo(d['title']) # typer.echo(d['title'])
def get_children(data, url, acc, count: int = 0, worklist=[]): def get_children(worklist, url, acc, count: int = 0):
count = count + 1 count = count + 1
typer.echo(f'kommer hit: {count}') typer.echo(f'kommer hit: {count}')
# print("The acc is: ", acc) # print("The acc is: ", acc)
...@@ -99,9 +98,10 @@ def get_children(data, url, acc, count: int = 0, worklist=[]): ...@@ -99,9 +98,10 @@ def get_children(data, url, acc, count: int = 0, worklist=[]):
if len(worklist) == 0: if len(worklist) == 0:
return acc return acc
else: else:
data = worklist.pop()
id = data['id'] id = data['id']
old = f'{url}/{id}/children' old = f'{url}/{id}/children'
typer.echo(url) # typer.echo(url)
response = requests.get(old, cookies = cookies) response = requests.get(old, cookies = cookies)
if response.status_code == 403 or response.status_code == 404: if response.status_code == 403 or response.status_code == 404:
typer.echo(response.json()['status']) typer.echo(response.json()['status'])
...@@ -109,22 +109,13 @@ def get_children(data, url, acc, count: int = 0, worklist=[]): ...@@ -109,22 +109,13 @@ def get_children(data, url, acc, count: int = 0, worklist=[]):
return acc return acc
else: else:
child = response.json()['results'] child = response.json()['results']
worklist.append(child) for i in range(len(child)):
acc = acc + child if key in child[i] and child[i][key] == True:
parent = worklist.pop() worklist.append(child[i])
return get_children(parent, url, acc, count, worklist) else:
acc.append(child[i])
def get_children2(d, url): # parent = worklist.pop()
key = 'hasChildren' return get_children(worklist, url, acc, count)
while key in d and d[key] == True:
id = d['id']
url = f'{url}{id}/children'
typer.echo()
typer.echo(url)
typer.echo()
response = requests.get(url, cookies=cookies)
child = response.json()['results']
return child
...@@ -136,23 +127,14 @@ def get_assignments(course_id: str = typer.Argument('_27251_1', help='The course ...@@ -136,23 +127,14 @@ def get_assignments(course_id: str = typer.Argument('_27251_1', help='The course
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()['results'] data = x.json()['results']
# parent_id = data[8]['id'] root = data[8]
# name = data[8]['title'] # root = Node(data[8])
# parent = Node(parent_id+name) worklist = [root]
# print(parent['id']) res = get_children(worklist, url, [])
root = Node(data[8])
res = get_children(root, url, [])
# res = get_children2(data[2], url)
for i in res: for i in res:
print(i['title']) print(i['title'])
#typer.echo(ptyper.echo.ptyper.echo(res))
# for data in res:
# typer.echo(d['title'])
#typer.echo(ptyper.echo.ptyper.echo(data))
#for d in data:
#typer.echo()
#typer.echo(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