-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlate.py
executable file
·59 lines (50 loc) · 1.39 KB
/
late.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
from subprocess import Popen, PIPE
import csv
import sys
import datetime
from bookkeeping import *
from mailer import *
time_index = 0
user_index = 1
days_index = 2
assign_index = 3
errors = 0
error_list = []
if len(sys.argv) != 3 or (not sys.argv[1].endswith(".csv")):
print "Usage: python late.py <file.csv> <homework_number>"
exit()
target_hw = sys.argv[2]
cur_map = {}
total_map = {}
f = csv.reader(open(sys.argv[1]))
print "Parsing file..."
for line in f:
if len(line) != 4:
error_list.append(line)
errors += 1
continue
#while iterating over the lines, add to map (check if it exists before)
date = line[time_index]
net_id = line[user_index]
homework_num = line[assign_index]
lateday_num = line[days_index]
if homework_num != target_hw:
continue
cur_info = bookkeeper(date, net_id, lateday_num, homework_num)
#Add to all their submissions
if not net_id in total_map:
total_map[net_id] = []
total_map[net_id].append(cur_info)
#Only keep the latest submission in the map
if net_id in cur_map and date <= cur_map[net_id].timestamp:
continue
else:
cur_map[net_id] = cur_info
print "Sending results to students"
for kid in cur_map:
sendKidMail(total_map[kid], cur_map[kid])
print "Sending results to course staff..."
sendStaffMail(cur_map, target_hw, error_list)
print "Done sending mail..."
print "Error summary:"
print "\t" + str(errors) + " errors"