legislation cache working now too

This commit is contained in:
Moses Rolston 2025-03-08 15:13:55 -08:00
parent be101beac8
commit 84156a1ce9

View File

@ -61,7 +61,14 @@ def get_sponsored():
neo4j_logger.error(f"Failed to fetch sponsored legislation for bioguideId {current_bioguideId}: Status Code {response.status_code}, Response: {response.text}") neo4j_logger.error(f"Failed to fetch sponsored legislation for bioguideId {current_bioguideId}: Status Code {response.status_code}, Response: {response.text}")
continue continue
sponsored_legislation = response.json().get('sponsoredLegislation', []) response_data = response.json()
# Ensure the response contains 'sponsoredLegislation' key
if 'sponsoredLegislation' not in response_data:
neo4j_logger.error(f"Missing 'sponsoredLegislation' key in response for bioguideId {current_bioguideId}: {response_data}")
continue
sponsored_legislation = response_data['sponsoredLegislation']
# Step 3: Store each piece of legislation in the cache along with the sponsor bioguideId # Step 3: Store each piece of legislation in the cache along with the sponsor bioguideId
for legislation in sponsored_legislation: for legislation in sponsored_legislation:
@ -74,15 +81,23 @@ def get_sponsored():
if key not in cache: if key not in cache:
# Ensure all nested dictionaries are handled properly # Ensure all nested dictionaries are handled properly
latest_action = legislation.get('latestAction')
# Check if latest_action is None before calling .get()
if latest_action is None:
latest_action = {}
policy_area = legislation.get('policyArea', {})
legislation_info = { legislation_info = {
'bioguideId': current_bioguideId, 'bioguideId': current_bioguideId,
**legislation, **legislation,
'latestAction': { 'latestAction': {
'actionDate': legislation['latestAction']['actionDate'], 'actionDate': latest_action.get('actionDate'),
'text': legislation['latestAction']['text'] 'text': latest_action.get('text')
}, },
'policyArea': { 'policyArea': {
'name': legislation['policyArea']['name'] 'name': policy_area.get('name')
} }
} }