-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_database_json.py
More file actions
60 lines (51 loc) · 1.48 KB
/
create_database_json.py
File metadata and controls
60 lines (51 loc) · 1.48 KB
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
# Reads people.csv - Header : Email, Name, Class, Graduation Year
from pprint import pprint
import random
import copy
import json
import sys
TEST = '--test' in sys.argv
with open('people.csv' if not TEST else 'people-test.csv', 'r') as people_file:
raw_people = people_file.read()
people = []
for person in raw_people.split('\n'):
email, name, class_number, year = person.split(',')
email = email.replace('.', '')
person = {
'email': email,
'name': name,
'class': class_number,
'year': year
}
people.append(person)
shuffled_people = copy.copy(people)
random.shuffle(shuffled_people)
targets = {}
taggers = {}
out = {}
names = {}
numTags = {}
classes = {}
for i, person in enumerate(shuffled_people):
if i == len(shuffled_people) - 1:
target_email = shuffled_people[0]['email']
targets[person['email']] = target_email
taggers[target_email] = person['email']
else:
target_email = shuffled_people[i+1]['email']
targets[person['email']] = target_email
taggers[target_email] = person['email']
out[person['email']] = False
names[person['email']] = person['name']
numTags[person['email']] = 0
classes[person['email']] = person['class']
database = {
'targets': targets,
'taggers': taggers,
'out': out,
'names': names,
'numTags': numTags,
'classes': classes
}
with open('database.json', 'w') as database_file:
database_file.write(json.dumps(database, indent=4))