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
07326030
Commit
07326030
authored
2 years ago
by
williamforbrigd
Browse files
Options
Downloads
Patches
Plain Diff
show the content of a specific folder
parent
8a664b69
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bbcli/__init__.py
+1
-1
1 addition, 1 deletion
bbcli/__init__.py
bbcli/endpoints.py
+55
-22
55 additions, 22 deletions
bbcli/endpoints.py
bbcli/entities/Node.py
+2
-3
2 additions, 3 deletions
bbcli/entities/Node.py
with
58 additions
and
26 deletions
bbcli/__init__.py
+
1
−
1
View file @
07326030
...
...
@@ -4,7 +4,7 @@
__app_name__
=
"
bbcli
"
__version__
=
"
0.1.0
"
# from .endpoints import *
from
.Node
import
*
#
from
.entities
.Node import *
from
.utils.utils
import
*
from
.services
import
login
# from endpoints import get_user, get_course, get_assignments, get_course_contents
...
...
This diff is collapsed.
Click to expand it.
bbcli/endpoints.py
+
55
−
22
View file @
07326030
...
...
@@ -5,12 +5,13 @@ import requests
import
bbcli.cli
as
cli
import
click
import
os
from
colorama
import
Fore
,
Style
from
anytree
import
Node
as
Nd
,
RenderTree
from
bbcli
import
check_response
from
bbcli.Node
import
Node
from
bbcli.
entities.
Node
import
Node
base_url
=
'
https://ntnu.blackboard.com/learn/api/public/v1/
'
...
...
@@ -85,7 +86,7 @@ def get_course_contents(course_id: str):
click
.
echo
(
map
)
def
get_children
(
session
,
worklist
,
url
,
acc
,
count
:
int
=
0
):
def
get_children
(
session
,
worklist
,
url
,
acc
,
count
:
int
=
0
,
is_root
=
True
):
count
=
count
+
1
key
=
'
hasChildren
'
if
len
(
worklist
)
==
0
:
...
...
@@ -93,7 +94,10 @@ def get_children(session, worklist, url, acc, count: int = 0):
else
:
node
=
worklist
.
pop
()
id
=
node
.
data
[
'
id
'
]
old
=
f
'
{
url
}
/
{
id
}
/children
'
if
is_root
is
False
:
old
=
f
'
{
url
}
/children
'
else
:
old
=
f
'
{
url
}
/
{
id
}
/children
'
response
=
session
.
get
(
old
,
cookies
=
cli
.
cookies
)
if
check_response
(
response
)
==
False
:
return
acc
...
...
@@ -116,50 +120,79 @@ def create_tree(root, nodes):
root_node
=
Nd
(
root
.
data
[
'
title
'
])
parent
=
root_node
parents
.
append
(
parent
)
colors
=
dict
()
folders
=
dict
()
colors
[
root
.
data
[
'
title
'
]]
=
True
folders
[
root
.
data
[
'
title
'
]]
=
root
.
data
[
'
id
'
]
for
i
in
range
(
len
(
nodes
)):
if
(
nodes
[
i
].
children
and
nodes
[
i
]
not
in
parents
):
# if (nodes[i].has_children and nodes[i] not in parents):
id
=
nodes
[
i
].
data
[
'
id
'
]
title
=
nodes
[
i
].
data
[
'
title
'
]
if
(
nodes
[
i
].
has_children
):
for
parent
in
parents
:
if
(
parent
==
nodes
[
i
].
parent
.
data
[
'
title
'
]):
node
=
Nd
(
nodes
[
i
].
data
[
'
title
'
],
parent
)
if
(
parent
.
name
==
nodes
[
i
].
parent
.
data
[
'
title
'
]):
node
=
Nd
(
title
,
parent
)
folders
[
title
]
=
id
parents
.
append
(
node
)
continue
node
=
Nd
(
nodes
[
i
].
data
[
'
title
'
],
root_node
)
node
=
Nd
(
title
,
root_node
)
folders
[
title
]
=
id
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
):
# elif (nodes[i].has_children):
# for parent in parents:
# if (nodes[i].parent.data['title'] == parent):
# node = Nd(node.data['title'], parent)
# folders[title] == id
# if (nodes[i].has_children is False):
else
:
for
parent
in
parents
:
if
(
parent
.
name
==
nodes
[
i
].
parent
.
data
[
'
title
'
]):
node
=
Nd
(
nodes
[
i
].
data
[
'
title
'
],
parent
)
node
=
Nd
(
title
,
parent
)
folders
[
title
]
=
''
for
pre
,
fill
,
node
in
RenderTree
(
root_node
):
print
(
"
%s%s
"
%
(
pre
,
node
.
name
))
folder_id
=
folders
[
node
.
name
]
if
folder_id
==
''
:
print
(
"
%s%s
"
%
(
pre
,
node
.
name
))
else
:
print
(
f
'
{
pre
}{
Fore
.
BLUE
}{
folder_id
}
{
node
.
name
}
{
Style
.
RESET_ALL
}
'
)
@click.command
(
name
=
'
get-assignments
'
)
@click.argument
(
'
course_id
'
,
default
=
'
_27251_1
'
)
def
get_assignments
(
course_id
:
str
):
@click.option
(
'
--folder-id
'
)
def
get_assignments
(
course_id
:
str
,
folder_id
=
None
):
'''
Get the assignments
Get the assignments
\n
Folders are blue and have an id
\n
Files are white
'''
session
=
requests
.
Session
()
url
=
f
'
{
base_url
}
courses/
{
course_id
}
/contents
'
if
folder_id
is
not
None
:
url
=
f
'
{
base_url
}
courses/
{
course_id
}
/contents/
{
folder_id
}
'
else
:
url
=
f
'
{
base_url
}
courses/
{
course_id
}
/contents
'
start
=
time
.
time
()
response
=
session
.
get
(
url
,
cookies
=
cli
.
cookies
)
if
check_response
(
response
)
==
False
:
return
else
:
data
=
response
.
json
()[
'
results
'
]
for
root
in
data
:
root
=
Node
(
root
,
True
)
if
folder_id
is
not
None
:
data
=
response
.
json
()
# print(len(data))
root
=
Node
(
data
,
True
)
worklist
=
[
root
]
res
=
get_children
(
session
,
worklist
,
url
,
[])
res
=
get_children
(
session
,
worklist
,
url
,
[]
,
is_root
=
False
)
create_tree
(
root
,
res
)
else
:
data
=
response
.
json
()[
'
results
'
]
for
root
in
data
:
root
=
Node
(
root
,
True
)
worklist
=
[
root
]
res
=
get_children
(
session
,
worklist
,
url
,
[])
create_tree
(
root
,
res
)
end
=
time
.
time
()
print
(
f
'
\n
download time:
{
end
-
start
}
seconds
'
)
This diff is collapsed.
Click to expand it.
bbcli/Node.py
→
bbcli/
entities/
Node.py
+
2
−
3
View file @
07326030
class
Node
(
object
):
def
__init__
(
self
,
data
,
children
,
parent
=
None
):
def
__init__
(
self
,
data
,
has_
children
,
parent
=
None
):
self
.
data
=
data
self
.
children
=
children
self
.
has_
children
=
has_
children
#bool
self
.
parent
=
parent
self
.
children
=
children
#bool
# if children is not None:
# for child in children:
# self.add_child(child)
...
...
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