-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.py
More file actions
85 lines (63 loc) · 2.71 KB
/
Copy pathsync.py
File metadata and controls
85 lines (63 loc) · 2.71 KB
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
84
85
import datetime
import json
import traceback
import canvasapi.exceptions
import trello.exceptions
from canvashelper import get_upcoming_assignments
from trellohelper import add_assignments
from secrets import CLASS_LIST_DICT
# Patched version of Trello's fetch_json to fix 403 error
# See https://github.com/sarumont/py-trello/issues/376 for updates on repo maintenance
import trello
def patched_fetch_json(self,
uri_path,
http_method='GET',
headers=None,
query_params=None,
post_args=None,
files=None):
""" Fetch some JSON from Trello """
# explicit values here to avoid mutable default values
if headers is None:
headers = {}
if query_params is None:
query_params = {}
if post_args is None:
post_args = {}
# if files specified, we don't want any data
data = None
if files is None and post_args != {}:
data = json.dumps(post_args)
# set content type and accept headers to handle JSON
if http_method in ("POST", "PUT", "DELETE") and not files:
headers['Content-Type'] = 'application/json; charset=utf-8'
headers['Accept'] = 'application/json'
# construct the full URL without query parameters
if uri_path[0] == '/':
uri_path = uri_path[1:]
url = 'https://api.trello.com/1/%s' % uri_path
if self.oauth is None:
query_params['key'] = self.api_key
query_params['token'] = self.api_secret
# perform the HTTP requests, if possible uses OAuth authentication
response = self.http_service.request(http_method, url, params=query_params,
headers=headers, data=data,
auth=self.oauth, files=files,
proxies=self.proxies)
if response.status_code == 401:
raise trello.Unauthorized("%s at %s" % (response.text, url), response)
if response.status_code != 200:
raise trello.ResourceUnavailable("%s at %s" % (response.text, url), response)
return response.json()
trello.TrelloClient.fetch_json = patched_fetch_json
def main():
print(f'[{datetime.datetime.now()}] Checking assignments...')
for class_id in CLASS_LIST_DICT.keys():
try:
upcoming_assignments = get_upcoming_assignments(class_id)
add_assignments(class_id, upcoming_assignments)
except trello.exceptions.ResourceUnavailable or canvasapi.exceptions.CanvasException as e:
print(f'Error fetching assignments and updating cards for course: {class_id}')
traceback.print_exc()
if __name__ == '__main__':
main()