Skip to content

Commit 3d240bf

Browse files
AlexCatarinoclaude
andcommitted
Support renamed 'states' and 'countries' agency keys
As of 2025-02-03, the Regalytics 'agencies' field uses 'states' and 'countries' instead of 'state' and 'country'. Read the new keys with fallback to the legacy ones so older articles keep working. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b97be5d commit 3d240bf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

process.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ def fetch(page):
4646

4747
return [page_1] + remaining
4848

49+
# example of agencies field in the article data:
50+
# On February 3, 2025, the keys in the `agencies` field became `states` and `countries`, instead of `state` and `country`.
4951
# "agencies": [
5052
# {
5153
# "name": "Iowa Department of Human Services",
52-
# "state": [
54+
# "states": [
5355
# {
5456
# "name": "Iowa"
5557
# }
5658
# ],
57-
# "country": [
59+
# "countries": [
5860
# {
5961
# "name": "United States"
6062
# }
@@ -78,12 +80,13 @@ def process(process_date):
7880
states = {}
7981
agencies = article.get('agencies') or []
8082
for agency in agencies:
81-
state = agency.get('state')
83+
state = agency.get('states') or agency.get('state') or []
8284
if not state:
8385
continue
8486

8587
state_names = [x['name'] for x in state]
86-
for country in agency.get('country', []):
88+
countries = agency.get('countries') or agency.get('country') or []
89+
for country in countries:
8790
states.setdefault(country['name'], []).extend(state_names)
8891

8992
article['states'] = states

0 commit comments

Comments
 (0)