Skip to content
Snippets Groups Projects
Commit 2ee52373 authored by Mattias Eggen's avatar Mattias Eggen
Browse files

tmp

parent 36717acb
No related branches found
No related tags found
No related merge requests found
class Node:
def __init__(self, data, children=[]):
self.root = root
self.children = children
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)
\ No newline at end of file
......@@ -4,6 +4,7 @@
__app_name__ = "bbcli"
__version__ = "0.1.0"
from .endpoints import *
from .Node import *
(
SUCCESS,
......
......@@ -7,9 +7,10 @@ import typer
import click
from typing import Optional
from dotenv import load_dotenv
from anytree import Node, RenderTree
import os
from bbcli import Node
app = typer.Typer()
......@@ -90,16 +91,14 @@ def get_course_contents(course_id: str = '_27251_1'):
# for d in data:
# typer.echo(d['title'])
def get_children(data, url, acc, count: int = 0):
def get_children(data, url, acc, count: int = 0, worklist=[]):
count = count + 1
typer.echo(f'kommer hit: {count}')
# print("The acc is: ", acc)
key = 'hasChildren'
if key not in data or data[key] == False:
typer.echo('nei')
if len(worklist) == 0:
return acc
else:
typer.echo('ja')
id = data['id']
old = f'{url}/{id}/children'
typer.echo(url)
......@@ -110,8 +109,10 @@ def get_children(data, url, acc, count: int = 0):
return acc
else:
child = response.json()['results']
worklist.append(child)
acc = acc + child
return get_children(child, url, acc, count)
parent = worklist.pop()
return get_children(parent, url, acc, count, worklist)
def get_children2(d, url):
key = 'hasChildren'
......@@ -139,7 +140,8 @@ def get_assignments(course_id: str = typer.Argument('_27251_1', help='The course
# name = data[8]['title']
# parent = Node(parent_id+name)
# print(parent['id'])
res = get_children(data[8], url, [])
root = Node(data[8])
res = get_children(root, url, [])
# res = get_children2(data[2], url)
for i in res:
......
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