-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.py
75 lines (60 loc) · 2.07 KB
/
parser.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
75
import sys
import csv
from hack import Hackathon, Expo, Hack
# Parse command_line arguments
file_list = sys.argv[1:]
csv_file_list = []
# Metadata column numbers (0 is the first column)
# Defaults are consistent with most (BUT NOT ALL) DevPost export formats
COL_NUM_OF = COLUMN_NUMBERS = {
'SUBMISSION_TITLE': 0,
'SUBMISSION_URL': 1,
'SPONSOR_LIST': 6,
'ROUTE': 7
}
# Number of table spots
HACKS_PER_EXPO_MAX = 100
HACKS_PER_JUDGE = 30
# [Assumes two expos]
OUTPUT_FILE_NAME = 'output.csv'
def split_list(a_list):
# Utility to split route hack lists
half = len(a_list)/2
return a_list[:half], a_list[half:]
##### Begin flow #####
# Inspect files
for name in file_list:
if not name.endswith('.csv'):
print("File \"%s\" is not in csv format." % name)
exit(1)
csv_file_list.append(name)
# Instantiate PennApps!
pennapps = Hackathon()
# Instantiate expos
expo_1 = Expo(pennapps, HACKS_PER_EXPO_MAX)
expo_2 = Expo(pennapps, HACKS_PER_EXPO_MAX)
pennapps.add_expo(expo_1)
pennapps.add_expo(expo_2)
# Set judge codes
pennapps.set_judge_codes(['Will', 'Jake', 'Shaanan', 'Sri', 'Thomas', 'Brian', 'Simran', 'Wissman' ])
# Parse and create results
for csv_file in csv_file_list:
with open(csv_file, "rU") as csvfile:
# Delimeter and quotechar are optional
csv_iterator = csv.reader(csvfile)
# Get first row columns
first_row = (csv_iterator)
for row in csv_iterator:
new_hack = Hack(name=row[COL_NUM_OF['SUBMISSION_TITLE']],
url=row[COL_NUM_OF['SUBMISSION_URL']],
sponsor_list=row[COL_NUM_OF['SPONSOR_LIST']],
route=row[COL_NUM_OF['ROUTE']],
hackathon=pennapps
)
pennapps.add_hack(new_hack)
# Split by route
for route in pennapps.routes.keys():
A, B = split_list(list(pennapps.routes[route]))
expo_1.add_hacks_by_list(A)
expo_2.add_hacks_by_list(B)
pennapps.write_to_csv('output.csv', HACKS_PER_JUDGE)