forked from mmcinnestaylor/Programming-Contest-Suite
-
Notifications
You must be signed in to change notification settings - Fork 2
/
course_csv_gen.py
69 lines (48 loc) · 2.22 KB
/
course_csv_gen.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
import csv, random
while True:
write_csv = input("[W]rite to CSV or [P]rint to console?: ")
if write_csv == 'W' or write_csv == 'w' or write_csv == 'P' or write_csv == 'p':
break
else:
print('Invalid input. Please enter W or P [case insensitive].\n')
continue_input = 'Y'
# Print Course IDs to the terminal
if write_csv == 'P' or write_csv == 'p':
while continue_input == 'Y' or continue_input == 'y':
course_code = input("\nCourse code [ex. COP3014]: ")
instructor = input("Instructor CS email [excluding @cs.fsu.edu]: ")
to_hash = course_code + instructor
id = hash(to_hash)
if id < 0:
id *= -1
print('\n' + 'Course ID: ' + str(id)[:8] + '\n')
continue_input = input("Enter another [y/n]: ")
# Write Course Data to CSV file for Django import
else:
try:
with open("courses.csv", "w") as f:
coursewriter = csv.writer(f, delimiter=',', quoting=csv.QUOTE_MINIMAL)
coursewriter.writerow(['id', 'code', 'name', 'instructor'])
used_ids = []
while continue_input == 'Y' or continue_input == 'y':
course_code = input("\nCourse code [ex. COP3014]: ")
course_name = input("Course name [ex. Programming I]: ")
instructor = input("Instructor CS email [excluding @cs.fsu.edu]: ")
correct_entry = input(
'\n'+course_code+'\t'+course_name+'\t'+instructor+"\n\nIs the entry correct [y/n]?: ")
if correct_entry == 'N' or correct_entry =='n':
continue
to_hash = course_code + instructor
id = hash(to_hash)
if id < 0:
id *= -1
id = str(id)[:8]
while id in used_ids:
id_list = list(id)
random.shuffle(id_list)
id = ''.join(id_list)
used_ids.append(id)
coursewriter.writerow([id, course_code, course_name, instructor+'@cs.fsu.edu'])
continue_input = input("Enter another [y/n]: ")
except IOError:
print('Error creating output file. Please retry.\n')