-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_legislators.py
43 lines (30 loc) · 1.01 KB
/
import_legislators.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
import os
import pymongo
import bson
import json
import csv
APP_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = "{0}/data/congress-legislators/".format(APP_DIR)
from conf.vance import DB, DB_HOST, DB_USER, DB_PASS
db = pymongo.MongoClient(DB_HOST).congress
db.legislator.drop()
db.create_collection("legislator")
def process_legislators(legislators):
headers = legislators.next()
print headers
while True:
leg_dict = {}
try :
leg = legislators.next()
except StopIteration:
break
for i in range(0, len(headers)):
leg_dict[headers[i]] = leg[i]
db.legislator.insert(leg_dict)
with open("{0}/legislators-historic.csv".format(DATA_DIR), 'rb') as csvfile:
legislators = csv.reader(csvfile)
process_legislators(legislators)
with open("{0}/legislators-current.csv".format(DATA_DIR), 'rb') as csvfile:
legislators = csv.reader(csvfile)
process_legislators(legislators)
db.legislator.create_index("thomas_id")