-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_loader.py
107 lines (92 loc) · 2.79 KB
/
data_loader.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker
import json
from models import legislator, bill, committee, committee_member, vote, bill_committee
engine = create_engine('mysql+mysqldb://phub:@localhost/phub?charset=utf8')
Session = sessionmaker(bind=engine)
session = Session()
engine.echo = True
bio_to_id = {}
with open('data/rep_data.json', 'r') as infile:
data = json.load(infile)
for key in data:
info = data[key]
bio_to_id[info['bioguide_id']] = info['id']
curr_rep = legislator(
id = key,
first_name = info['first_name'],
last_name = info['last_name'],
chamber = info['chamber'],
gender = info['gender'],
birthday = info['birthday'],
party = info['party'],
state = info['state'],
twitter = info['twitter'],
website = info['website'],
bio_guide = info['bioguide_id'],
contact_form = info['contact_form'],
image = info['image_jpg'])
session.merge(curr_rep)
with open('data/bill_data.json', 'r') as infile:
data = json.load(infile)
for key in data:
info = data[key]
if 'sponsor' in info:
sponsor = bio_to_id[info['sponsor']['id']]
else:
sponsor = None
cur_bill = bill(
id = key,
name = info['name'],
bill_type = info['bill_type'],
bill_id = info['bill_id'],
date_intro = info['date_introduced'],
house_status = info['house_status'],
senate_status = info['senate_status'],
link = info['link'],
current_status_label = info['current_status_label'],
current_status_description = info['current_status_description'],
current_status = info['current_status'],
fk_sponsor = sponsor)
session.merge(cur_bill)
with open('data/committee_data.json', 'r') as infile:
data = json.load(infile)
for key in data:
info = data[key]
if 'chair' in info:
chair = bio_to_id[info['chair']['id']]
else:
chair = None
cur_com = committee(
id = key,
name = info['name'],
chamber = info['chamber'],
website = info['website'],
jurisdiction = info['jurisdiction'],
is_subcommittee = info['is_subcommittee'],
committee_id = info['committee_id'],
fk_chair = chair)
session.merge(cur_com)
data = json.load(open('data/committee_members_data.json'))
for l,c in data:
curr = committee_member(
legislator_id = int(l),
committee_id = int(c)
)
session.merge(curr)
data = json.load(open('data/votes_data.json'))
for l,b,r in data:
curr = vote(
legislator_id = int(l),
bill_id = int(b),
result = r
)
session.merge(curr)
data = json.load(open('data/bill_committee_data.json'))
for b,c in data:
curr = bill_committee(
bill_id = int(b),
committee_id = int(c)
)
session.merge(curr)
session.commit()