-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgrade6.py
73 lines (56 loc) · 2.41 KB
/
grade6.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
####################################
# grade6.py #
# #
# Brahm Gardner #
# Jason Hirschhorn #
# Doug Lloyd #
# #
# Last revised: 2016-10-31 18:10 #
####################################
import os, check50
def main():
# list of files this script catches
recreated_files = ['caesar', 'crack', 'credit', 'greedy', 'mario', 'vigenere']
new_files = ['smile', 'tweets']
# message
print("Automatically grading Problem Set 6...")
# set the root to be the current directory
rootdir = './'
# get a list of all student directories in the root
directories = [d for d in os.listdir(rootdir) if os.path.isdir(os.path.join(rootdir, d))]
# create a results directory if you don't already have one
try:
os.stat(rootdir + "results")
except:
os.mkdir(rootdir + "results")
# iterate over those directories
for directory in directories:
# ignore the results directory
if directory == "results" or directory == ".git" or directory[0] == "_":
continue
# ignore empty directories
if not os.listdir(directory):
continue
# start a file for this student's check50 output
f = open(rootdir + "results/" + directory + ".txt", "w")
f.write("+------------------+\n\n")
# breadcrumbs
print("Now grading student {}...".format(directory))
# run all possible checks on the remakes
check50.mario("{}{}".format(rootdir, directory), f)
check50.greedy("{}{}".format(rootdir, directory), f)
check50.credit("{}{}".format(rootdir, directory), f)
check50.caesar("{}{}".format(rootdir, directory), f)
check50.vigenere("{}{}".format(rootdir, directory), f)
check50.crack(f)
# run checks on smile and tweets
check50.smile("{}{}".format(rootdir, directory + "/sentiments"), f)
twitter = {'key': 'TODO',
'secret': 'TODO'}
check50.tweets("{}{}".format(rootdir, directory + "/sentiments"), f, twitter)
f.close()
print("...grading complete!")
print("Student reports are now ready in the results/ directory.")
# execute process
if __name__ == "__main__":
main()