Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
IDATT2900-072
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattias Agentoft Eggen
IDATT2900-072
Commits
c61fb477
Commit
c61fb477
authored
3 years ago
by
magnus2142
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' of gitlab.stud.idi.ntnu.no:mattiaae/idatt2900-072 into main
parents
4c181fb9
91745325
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bbcli/Node.py
+7
-20
7 additions, 20 deletions
bbcli/Node.py
bbcli/endpoints.py
+54
-30
54 additions, 30 deletions
bbcli/endpoints.py
with
61 additions
and
50 deletions
bbcli/Node.py
+
7
−
20
View file @
c61fb477
class
Node
(
object
):
def
__init__
(
self
,
data
,
children
=
None
):
def
__init__
(
self
,
data
,
children
,
parent
=
None
):
self
.
data
=
data
self
.
children
=
children
if
children
is
not
None
:
for
child
in
children
:
self
.
add_child
(
child
)
self
.
parent
=
parent
self
.
children
=
children
#bool
# if children is not None:
# for child in children:
# self.add_child(child)
def
add_child
(
self
,
node
):
assert
isinstance
(
node
,
Node
)
self
.
chilren
.
append
(
node
)
# 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)
self
.
chilren
.
append
(
node
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
bbcli/endpoints.py
+
54
−
30
View file @
c61fb477
from
venv
import
create
import
requests
#from requests.auth import HTTPBasicAuth
# import json
# import pprint
import
bbcli.cli
as
cli
#from string_builder import StringBuilder
import
click
# from typing import Optional
# from dotenv import load_dotenv
# from anytree import Node, RenderTree
import
os
from
anytree
import
Node
as
Nd
,
RenderTree
from
bbcli
import
check_response
from
bbcli.Node
import
Node
base_url
=
'
https://ntnu.blackboard.com/learn/api/public/v1/
'
...
...
@@ -39,8 +35,8 @@ def get_user(user_name: str):
sn
=
data
[
'
name
'
][
'
family
'
]
id
=
data
[
'
studentId
'
]
click
.
echo
(
f
'
Name of the s
tudent:
{
fn
}
{
sn
}
'
)
click
.
echo
(
f
'
The s
tudent
id
:
{
id
}
'
)
click
.
echo
(
f
'
S
tudent
name
:
{
fn
}
{
sn
}
'
)
click
.
echo
(
f
'
S
tudent
ID
:
{
id
}
'
)
@click.command
(
name
=
'
get-course
'
)
...
...
@@ -64,6 +60,7 @@ def get_course(course_id: str):
click
.
echo
(
name
)
click
.
echo
(
f
'
URL for the course:
{
course_url
}
'
)
@click.command
(
name
=
'
get-course-contents
'
)
@click.argument
(
'
course_id
'
,
default
=
'
_27251_1
'
)
def
get_course_contents
(
course_id
:
str
):
...
...
@@ -85,28 +82,61 @@ def get_course_contents(course_id: str):
click
.
echo
(
f
'
{
i
+
1
}
{
title
}
'
)
click
.
echo
(
map
)
def
get_children
(
worklist
,
url
,
acc
,
count
:
int
=
0
):
count
=
count
+
1
click
.
echo
(
f
'
kommer hit:
{
count
}
'
)
key
=
'
hasChildren
'
if
len
(
worklist
)
==
0
:
return
acc
else
:
data
=
worklist
.
pop
()
id
=
data
[
'
id
'
]
node
=
worklist
.
pop
()
id
=
node
.
data
[
'
id
'
]
old
=
f
'
{
url
}
/
{
id
}
/children
'
response
=
requests
.
get
(
old
,
cookies
=
cli
.
cookies
)
response
=
requests
.
get
(
old
,
cookies
=
cli
.
cookies
)
if
check_response
(
response
)
==
False
:
return
acc
else
:
child
=
response
.
json
()[
'
results
'
]
for
i
in
range
(
len
(
child
)):
if
key
in
child
[
i
]
and
child
[
i
][
key
]
==
True
:
worklist
.
append
(
child
[
i
])
children
=
response
.
json
()[
'
results
'
]
for
i
in
range
(
len
(
children
)):
# TODO: Add list of children instead of bool
if
key
in
children
[
i
]
and
children
[
i
][
key
]
==
True
:
child
=
Node
(
children
[
i
],
True
,
node
)
worklist
.
append
(
child
)
acc
.
append
(
child
)
else
:
acc
.
append
(
child
[
i
])
return
get_children
(
worklist
,
url
,
acc
,
count
)
child
=
Node
(
children
[
i
],
False
,
node
)
acc
.
append
(
child
)
return
get_children
(
worklist
,
url
,
acc
)
def
create_tree
(
root
,
nodes
):
parents
=
[]
root_node
=
Nd
(
root
.
data
[
'
title
'
])
parent
=
root_node
parents
.
append
(
parent
)
for
i
in
range
(
len
(
nodes
)):
if
(
nodes
[
i
].
children
and
nodes
[
i
]
not
in
parents
):
for
parent
in
parents
:
if
(
parent
==
nodes
[
i
].
parent
.
data
[
'
title
'
]):
node
=
Nd
(
nodes
[
i
].
data
[
'
title
'
],
parent
)
parents
.
append
(
node
)
continue
node
=
Nd
(
nodes
[
i
].
data
[
'
title
'
],
root_node
)
parents
.
append
(
node
)
elif
(
nodes
[
i
].
children
):
for
parent
in
parents
:
if
(
nodes
[
i
].
parent
.
data
[
'
title
'
]
==
parent
):
node
=
Nd
(
node
.
data
[
'
title
'
],
parent
)
if
(
nodes
[
i
].
children
is
False
):
for
parent
in
parents
:
if
(
parent
.
name
==
nodes
[
i
].
parent
.
data
[
'
title
'
]):
node
=
Nd
(
nodes
[
i
].
data
[
'
title
'
],
parent
)
for
pre
,
fill
,
node
in
RenderTree
(
root_node
):
print
(
"
%s%s
"
%
(
pre
,
node
.
name
))
@click.command
(
name
=
'
get-assignments
'
)
...
...
@@ -121,14 +151,8 @@ def get_assignments(course_id: str):
return
else
:
data
=
response
.
json
()[
'
results
'
]
root
=
data
[
8
]
# root = Node(data[8])
worklist
=
[
root
]
res
=
get_children
(
worklist
,
url
,
[])
for
i
in
res
:
print
(
i
[
'
title
'
])
for
root
in
data
:
root
=
Node
(
root
,
True
)
worklist
=
[
root
]
res
=
get_children
(
worklist
,
url
,
[])
create_tree
(
root
,
res
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment