Skip to content

Commit f52ded4

Browse files
committed
feat: add house members
1 parent 9426ac3 commit f52ded4

1,123 files changed

Lines changed: 1534429 additions & 48 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

congress/congress_members_scraper.py

Lines changed: 86 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -174,36 +174,68 @@ def convert_member_to_toml(self, member: Dict) -> Dict:
174174

175175
# Add memberships if available
176176
if member.get('memberships'):
177-
memberships = member['memberships']
178-
toml_data['membershipInfo'] = {
179-
'congress': memberships.get('congress', 0),
180-
'congressDesc': memberships.get('congress_desc', ''),
181-
'type': memberships.get('type', 0),
182-
'typeDesc': memberships.get('type_desc', ''),
183-
'district': memberships.get('district', 0),
184-
'partyListId': memberships.get('party_list', 0),
185-
'partyListName': memberships.get('party_list_name', '')
186-
}
187-
188-
# Add photo info
177+
memberships = member.get('memberships')
178+
# Check if memberships is a dict
179+
if isinstance(memberships, dict):
180+
toml_data['membershipInfo'] = {
181+
'congress': memberships.get('congress', 0),
182+
'congressDesc': memberships.get('congress_desc', ''),
183+
'type': memberships.get('type', 0),
184+
'typeDesc': memberships.get('type_desc', ''),
185+
'district': memberships.get('district', 0),
186+
'partyListId': memberships.get('party_list', 0),
187+
'partyListName': memberships.get('party_list_name', '')
188+
}
189+
elif isinstance(memberships, list) and memberships:
190+
# If memberships is a list, process all of them
191+
membership_list = []
192+
for mem in memberships:
193+
if isinstance(mem, dict):
194+
membership_list.append({
195+
'congress': mem.get('congress', 0),
196+
'congressDesc': mem.get('congress_desc', ''),
197+
'type': mem.get('type', 0),
198+
'typeDesc': mem.get('type_desc', ''),
199+
'district': mem.get('district', 0),
200+
'partyListId': mem.get('party_list', 0),
201+
'partyListName': mem.get('party_list_name', '')
202+
})
203+
if membership_list:
204+
toml_data['memberships'] = membership_list
205+
206+
# Add photo information
189207
if member.get('photo'):
190-
photo = member['photo']
191-
toml_data['photo'] = {
192-
'url': photo.get('url', ''),
193-
'size': photo.get('size', 0),
194-
'type': photo.get('type', '')
195-
}
208+
photo = member.get('photo')
209+
# Check if photo is a dict (not a list or other type)
210+
if isinstance(photo, dict):
211+
toml_data['photo'] = {
212+
'url': photo.get('url', ''),
213+
'size': photo.get('size', 0),
214+
'type': photo.get('type', '')
215+
}
216+
elif isinstance(photo, list) and photo:
217+
# If photo is a list, take the first element if it exists
218+
first_photo = photo[0] if photo else {}
219+
if isinstance(first_photo, dict):
220+
toml_data['photo'] = {
221+
'url': first_photo.get('url', ''),
222+
'size': first_photo.get('size', 0),
223+
'type': first_photo.get('type', '')
224+
}
196225

197226
# Add committee memberships
198227
if member.get('committee_membership'):
199228
committees = []
200-
for comm in member['committee_membership']:
201-
if comm:
202-
committees.append({
203-
'code': comm.get('committee_code', ''),
204-
'name': comm.get('name', ''),
205-
'title': comm.get('title', '')
206-
})
229+
committee_data = member.get('committee_membership', [])
230+
# Handle if committee_membership is a list
231+
if isinstance(committee_data, list):
232+
for comm in committee_data:
233+
if comm and isinstance(comm, dict):
234+
committees.append({
235+
'code': comm.get('committee_code', ''),
236+
'name': comm.get('name', ''),
237+
'title': comm.get('title', '')
238+
})
207239
if committees:
208240
toml_data['committees'] = committees
209241

@@ -212,18 +244,21 @@ def convert_member_to_toml(self, member: Dict) -> Dict:
212244
bills = []
213245
# Group bills by congress
214246
bills_by_congress = {}
215-
for bill in member['principal_authored_bills']:
216-
if bill:
217-
congress = bill.get('congress', 0)
218-
if congress not in bills_by_congress:
219-
bills_by_congress[congress] = []
220-
bills_by_congress[congress].append({
221-
'billNo': bill.get('bill_no', ''),
222-
'date': bill.get('date', ''),
223-
'name': bill.get('name', ''),
224-
'nameCode': bill.get('name_code', ''),
225-
'sequenceNo': bill.get('sequence_no', 0)
226-
})
247+
bills_data = member.get('principal_authored_bills', [])
248+
# Handle if principal_authored_bills is a list
249+
if isinstance(bills_data, list):
250+
for bill in bills_data:
251+
if bill and isinstance(bill, dict):
252+
congress = bill.get('congress', 0)
253+
if congress not in bills_by_congress:
254+
bills_by_congress[congress] = []
255+
bills_by_congress[congress].append({
256+
'billNo': bill.get('bill_no', ''),
257+
'date': bill.get('date', ''),
258+
'name': bill.get('name', ''),
259+
'nameCode': bill.get('name_code', ''),
260+
'sequenceNo': bill.get('sequence_no', 0)
261+
})
227262

228263
# Convert to list format
229264
for congress, congress_bills in sorted(bills_by_congress.items()):
@@ -241,17 +276,20 @@ def convert_member_to_toml(self, member: Dict) -> Dict:
241276
coauthored = []
242277
# Group bills by congress
243278
bills_by_congress = {}
244-
for bill in member['coauthored_bills']:
245-
if bill:
246-
congress = bill.get('congress', 0)
247-
if congress not in bills_by_congress:
248-
bills_by_congress[congress] = []
249-
bills_by_congress[congress].append({
250-
'billNo': bill.get('bill_no', ''),
251-
'date': bill.get('date', ''),
252-
'journalNo': bill.get('journal_no', ''),
253-
'sessionNo': bill.get('session_no', '')
254-
})
279+
bills_data = member.get('coauthored_bills', [])
280+
# Handle if coauthored_bills is a list
281+
if isinstance(bills_data, list):
282+
for bill in bills_data:
283+
if bill and isinstance(bill, dict):
284+
congress = bill.get('congress', 0)
285+
if congress not in bills_by_congress:
286+
bills_by_congress[congress] = []
287+
bills_by_congress[congress].append({
288+
'billNo': bill.get('bill_no', ''),
289+
'date': bill.get('date', ''),
290+
'journalNo': bill.get('journal_no', ''),
291+
'sessionNo': bill.get('session_no', '')
292+
})
255293

256294
# Convert to list format
257295
for congress, congress_bills in sorted(bills_by_congress.items()):

congress/house/members/all/..toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
id = 1026
2+
authorId = "."
3+
fullName = "P3PWD"
4+
lastName = "P3PWD"
5+
firstName = "."
6+
middleName = ""
7+
suffix = ""
8+
nickName = "."
9+
email = ""
10+
website = ""
11+
room = ""
12+
local = ""
13+
directLine = ""
14+
chiefOfStaff = ""
15+
partyAffiliation = 41
16+
partyAffiliationDesc = ""
17+
current = false
18+
lastScraped = "2025-09-23T02:52:23.513580"
19+
[[memberships]]
20+
congress = 19
21+
congressDesc = "19th Congress"
22+
type = 71
23+
typeDesc = "Party List Representative"
24+
district = 0
25+
partyListId = 41
26+
partyListName = "P3PWD"
27+
28+
[photo]
29+
url = "https://docs.congress.hrep.online/members/19th/._20250610164514_.jpg"
30+
size = 48906
31+
type = "image/jpeg"

congress/house/members/all/0.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id = 446
2+
authorId = "0"
3+
fullName = "Roman, Antonino P."
4+
lastName = "ROMAN"
5+
firstName = "ANTONINO"
6+
middleName = "PASCUAL"
7+
suffix = ""
8+
nickName = "Tony"
9+
email = ""
10+
website = ""
11+
room = ""
12+
local = ""
13+
directLine = ""
14+
chiefOfStaff = ""
15+
partyAffiliation = ""
16+
partyAffiliationDesc = ""
17+
current = false
18+
lastScraped = "2025-09-23T02:52:23.693758"

0 commit comments

Comments
 (0)