Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -342,32 +342,34 @@ def fetch_federal_register():
|
|
| 342 |
results = []
|
| 343 |
url = "https://www.federalregister.gov/api/v1/documents.json"
|
| 344 |
|
| 345 |
-
#
|
| 346 |
params = {
|
| 347 |
-
"conditions[term]":
|
| 348 |
"order": "newest",
|
| 349 |
"per_page": 10
|
| 350 |
}
|
| 351 |
|
| 352 |
try:
|
| 353 |
-
# We can use standard requests here! No stealth scraper needed for open APIs.
|
| 354 |
r = requests.get(url, params=params, timeout=15)
|
| 355 |
if r.status_code != 200:
|
| 356 |
-
print(f"Federal Register API returned status {r.status_code}")
|
| 357 |
return results
|
| 358 |
|
| 359 |
data = r.json()
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
title = doc.get("title", "No Title")
|
| 362 |
summary = doc.get("abstract", "No summary provided.")
|
| 363 |
link = doc.get("html_url", "")
|
| 364 |
action_type = doc.get("type", "Notice")
|
| 365 |
|
| 366 |
-
# The API gives us a clean list of agencies involved
|
| 367 |
agencies = doc.get("agency_names", ["Federal Agency"])
|
| 368 |
primary_agency = agencies[0] if agencies else "Federal Register"
|
| 369 |
|
| 370 |
-
# Parse the clean publication date
|
| 371 |
pub_date = doc.get("publication_date")
|
| 372 |
fmt_date = pd.to_datetime(pub_date).tz_localize(None).to_pydatetime() if pub_date else datetime.now()
|
| 373 |
|
|
|
|
| 342 |
results = []
|
| 343 |
url = "https://www.federalregister.gov/api/v1/documents.json"
|
| 344 |
|
| 345 |
+
# FIX: Simplify the search term. Complex boolean strings break their URL parser.
|
| 346 |
params = {
|
| 347 |
+
"conditions[term]": "artificial intelligence",
|
| 348 |
"order": "newest",
|
| 349 |
"per_page": 10
|
| 350 |
}
|
| 351 |
|
| 352 |
try:
|
|
|
|
| 353 |
r = requests.get(url, params=params, timeout=15)
|
| 354 |
if r.status_code != 200:
|
| 355 |
+
print(f"--> Federal Register API returned status {r.status_code}")
|
| 356 |
return results
|
| 357 |
|
| 358 |
data = r.json()
|
| 359 |
+
items = data.get("results", [])
|
| 360 |
+
|
| 361 |
+
# VERIFICATION: This will print the exact number of documents found to your terminal
|
| 362 |
+
print(f"--> Federal Register API: Found {len(items)} items.")
|
| 363 |
+
|
| 364 |
+
for doc in items:
|
| 365 |
title = doc.get("title", "No Title")
|
| 366 |
summary = doc.get("abstract", "No summary provided.")
|
| 367 |
link = doc.get("html_url", "")
|
| 368 |
action_type = doc.get("type", "Notice")
|
| 369 |
|
|
|
|
| 370 |
agencies = doc.get("agency_names", ["Federal Agency"])
|
| 371 |
primary_agency = agencies[0] if agencies else "Federal Register"
|
| 372 |
|
|
|
|
| 373 |
pub_date = doc.get("publication_date")
|
| 374 |
fmt_date = pd.to_datetime(pub_date).tz_localize(None).to_pydatetime() if pub_date else datetime.now()
|
| 375 |
|