-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
74 lines (64 loc) · 1.97 KB
/
cli.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
import argparse
import csv
import smtplib
import time
import webbrowser
from reminders.config import config, logger
from reminders.map import to_faculty_lists
from reminders.update_usernames import update_usernames
from reminders.notify import notify
# Meant to run on the CLI, args is an argparse object cast to a dict
def main(args):
if args["open_report"]:
webbrowser.open("https://vault.cca.edu/access/reports.do")
exit()
if args["update"]:
update_usernames()
exit()
with open(args["file"], "r") as fh:
reader = csv.DictReader(fh)
data = to_faculty_lists(reader)
# initialize SMTP server
if config.get("DEBUG"):
server = None
else:
server = smtplib.SMTP(config["SMTP_DOMAIN"], port=int(config["SMTP_PORT"]))
server.login(config["SMTP_USER"], config["SMTP_PASSWORD"])
for faculty in data:
logger.info("notifying {faculty}...".format(faculty=faculty))
notify(
faculty,
data[faculty]["username"],
data[faculty]["courses"],
server,
args["template"],
)
# not sure if necessary but I'd rather not spew out emails so fast
time.sleep(1)
if server is not None:
server.quit()
if __name__ == "__main__":
# CLI arguments
parser = argparse.ArgumentParser()
parser.add_argument(
"-u",
"--update",
help="update course data & faculty usernames",
action="store_true",
)
parser.add_argument(
"-o",
"--open-report",
help="open VAULT's Missing Syllabi report",
action="store_true",
)
parser.add_argument("file", nargs="?", help="CSV of missing syllabi report")
parser.add_argument(
"--template",
type=str,
choices=["initial", "followup", "final", "summer"],
help="which email template to utilize",
default="initial",
)
args = parser.parse_args()
main(vars(args))