generated from edgi-govdata-archiving/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
committees.py
executable file
·60 lines (54 loc) · 1.93 KB
/
committees.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
import json
import urllib.request
import sqlite3
import datetime
from os import path
conn = sqlite3.connect( 'leg_info.db' )
cursor = conn.cursor()
committees_url = 'https://theunitedstates.io/congress-legislators/committees-current.json'
members_url = 'https://theunitedstates.io/congress-legislators/committee-membership-current.json'
cmts = urllib.request.urlopen( committees_url ).read().decode()
obj = json.loads( cmts )
for cmt in obj:
print( cmt['name'] )
cmt_url = ''
jurisdiction = ''
try: cmt_url = cmt['url']
except KeyError: pass
try: jurisdiction = cmt['jurisdiction']
except KeyError: pass
cursor.execute(
'insert into committees ( committee_type, name, url, ' \
'committee_id, jurisdiction ) values ( ?,?,?,?,? )',
( cmt['type'], cmt['name'], cmt_url, cmt['thomas_id'],
jurisdiction ))
try:
scs = cmt['subcommittees']
for sc in scs:
cursor.execute(
'insert into sub_committees ( committee_id, name, ' \
'subcommittee_id ) values ( ?,?,? )',
( cmt['thomas_id'], sc['name'], sc['thomas_id'] ))
except KeyError:
pass
conn.commit()
mbrs = urllib.request.urlopen( members_url ).read().decode()
obj = json.loads( mbrs )
for cmt, mbrs in obj.items():
cmt_name = cmt[:4]
sub_name = cmt[4:]
for mbr in mbrs:
print( mbr['name'] )
start = ''
try:
start_date = datetime.datetime.strptime( mbr['start_date'],
'%Y-%m-%d' )
start = start_date.strftime( '%b %-d, %Y' )
except KeyError:
pass
cursor.execute(
'insert into committee_members ( name, bioguide_id, rank, ' \
'start, committee_id, subcommittee_id ) ' \
'values ( ?,?,?,?,?,? )', ( mbr['name'], mbr['bioguide'],
mbr['rank'], start, cmt_name, sub_name ))
conn.commit()