-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.py
83 lines (75 loc) · 3.2 KB
/
user.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import json, requests
from canvas import CanvasApi
from notion import NotionApi
class User:
def __init__(
self,
canvasKey,
notionToken,
notionPageId,
schoolAb,
database_id=None,
):
self.notionToken = notionToken
self.database_id = database_id
self.canvasProfile = CanvasApi(canvasKey, schoolAb)
self.page_ids = {"Default": notionPageId}
self.generated_db_id = None
self.schoolAb = schoolAb
self.notionProfile = NotionApi(
notionToken,
database_id=database_id,
schoolAb=schoolAb,
)
# Shorthand fucntion for getting list of courses that started within the past 6 months from Canvas
def getCoursesLastSixMonths(self):
return self.canvasProfile.get_courses_within_six_months()
# Shorthand fucntion for getting list of all courses from Canvas
def getAllCourses(self):
return self.canvasProfile.get_all_courses()
# Enters assignments into given database given (by id), or creates a new database, and fills the page with assignments not already found in the database
def enterAssignmentsToNotionDb(self, courseList):
if not self.notionProfile.test_if_database_id_exists():
self.notionProfile = NotionApi(
self.notionToken,
database_id=self.createDatabase(),
schoolAb=self.schoolAb,
)
self.addNewDatabaseItems(courseList)
else:
self.addNewDatabaseItems(courseList)
# Creates a new Canvas Assignments database in the notionPageId page
def createDatabase(self, page_id_name="Default"):
return self.notionProfile.createNewDatabase(self.page_ids[page_id_name])
# This function adds NEW assignments to the database based on whether the assignments URL can be found in the notion database
def addNewDatabaseItems(self, courseList):
self.canvasProfile.set_courses_and_id()
for course in courseList:
for assignment in self.canvasProfile.update_assignment_objects(
self.notionProfile.parseDatabaseForAssignments(),
course.name,
"future",
):
self.notionProfile.createNewDatabaseItem(
id=assignment["id"],
className=course.name,
dueDate={"start": assignment["due_at"]},
url=assignment["url"],
assignmentName=assignment["name"],
status="To Do",
)
# This function adds all found assignments to the notion database
def rawFillDatabase(self, courseList):
self.canvasProfile.set_courses_and_id()
for course in courseList:
for assignment in self.canvasProfile.get_assignment_objects(
course.name, "future"
):
self.notionProfile.createNewDatabaseItem(
id=assignment["id"],
className=course.name,
dueDate=assignment["due_at"],
url=assignment["url"],
assignmentName=assignment["name"],
status="To Do",
)