forked from dellsystem/ssuns-2011
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_ccm.py
executable file
·29 lines (24 loc) · 1023 Bytes
/
parse_ccm.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
#!/usr/bin/env python
# Generates the relevant SQL queries from the csv
# Some non-trivial processing involved so it can't be imported directly
import csv
# To use the sql-generating part:
# Uncomment lines 12, 22 and 24 (and comment out lines after 24)
# ./parse_ccm.py > ccm.sql
# Then edit the SQL and delete the last trailing comma
#print "INSERT INTO `ssuns_2011`.`country_committee_matrix` (`country_id`, `committee_id`, `num_delegates`) VALUES",
reader = csv.reader(open('ccm.csv', 'rt'))
country_id = 1 # It starts indexing from 1 for some reason
for row in reader:
# Ignore the first row
committees = row[1:]
for committee, num_delegates in enumerate(committees):
if num_delegates == '':
num_delegates = 0
#print "('%d', '%s', '%s')," % (country_id, committee, num_delegates)
country_id += 1
#print ";"
# Country-generating part, comment out if not needed
reader = csv.reader(open('ccm.csv', 'rt'))
for row in reader:
print "'%s'," % row[0].replace("'", "\\'")