-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcanvas_scraper.py
39 lines (28 loc) · 1.21 KB
/
canvas_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from canvasapi import Canvas
import config as config
from datetime import datetime
canvas = Canvas(config.CANVAS_API_URL, config.CANVAS_API_KEY)
user = canvas.get_user(config.CANVAS_USER_ID)
courses = user.get_courses()
# Get current classes
def get_current_courses():
current_classes = {}
for course in courses:
if (hasattr(course, 'enrollment_term_id') and course.enrollment_term_id == config.CANVAS_ENROLLMENT_TERM):
course_name = "".join(course.name[6:14].split())
print(course_name + " " + str(course.id))
current_classes[course.id] = course_name
return current_classes
# Get current assignments given list of courses
def get_current_assignments(current_classes):
current_assignments = {}
assignment_attrs = ['name', 'description',
'due_at_date', 'course_id', 'id', 'html_url', 'locked_for_user']
for c in current_classes.keys():
assignments = canvas.get_course(c).get_assignments()
for assignment in assignments:
a_dict = {}
for x in assignment_attrs:
a_dict[x] = getattr(assignment, x, "")
current_assignments[assignment.id] = a_dict
return current_assignments