-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeletedAssignments.py
66 lines (62 loc) · 2.5 KB
/
DeletedAssignments.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
import pandas as pd
import os, sys, shlex, subprocess, datetime, json, smtplib, logging
from sqlalchemy.engine import URL
from sqlalchemy import create_engine
from pathlib import Path
from timeit import default_timer as timer
from email.message import EmailMessage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from logging.handlers import SysLogHandler
from canvasapi import Canvas
from canvasapi.exceptions import CanvasException
"""
This script pulls ALL students from AERIES. Sorts them by site and grade, and puts them into a Canvas Course for the site,
and section in that course by Grade
"""
def main():
start_of_timer = timer()
WasThereAnError = False
confighome = Path.home() / ".Acalanes" / "Acalanes.json"
with open(confighome) as f:
configs = json.load(f)
if configs['logserveraddress'] is None:
logfilename = Path.home() / ".Acalanes" / configs['logfilename']
thelogger = logging.getLogger('MyLogger')
thelogger.basicConfig(filename=str(logfilename), level=thelogger.info)
else:
thelogger = logging.getLogger('MyLogger')
thelogger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address = (configs['logserveraddress'],514))
thelogger.addHandler(handler)
#prep status (msg) email
msg = EmailMessage()
msg['From'] = configs['SMTPAddressFrom']
msg['To'] = configs['SendInfoEmailAddr']
msgbody = ''
Canvas_API_URL = configs['CanvasAPIURL']
Canvas_API_KEY = configs['CanvasAPIKey']
canvas = Canvas(Canvas_API_URL,Canvas_API_KEY)
account = canvas.get_account(1)
course = canvas.get_course(11069)
assignments = course.get_assignments(workflow_state='deleted')
for assignment in assignments:
print(assignment)
print(assignment.workflow_state)
'''
end_of_timer = timer()
if WasThereAnError == True:
msg['Subject'] = "ERROR!! -> Canvas Catch-all Informational Course Update"
else:
msg['Subject'] = "Canvas Catch-all Informational Course Update"
msgbody += '\n\n Elapsed Time=' + str(end_of_timer - start_of_timer) + '\n'
msg.set_content(msgbody)
s = smtplib.SMTP(configs['SMTPServerAddress'])
s.send_message(msg)
thelogger.info('AUHSD Catchall Course Update->->Sent status message')
thelogger.info('AUHSD Catchall Course Update->->DONE! - took ' + str(end_of_timer - start_of_timer))
'''
print('Done!!!')
if __name__ == '__main__':
main()