Update query parameters and response handling in server.py

Replaced hardcoded date values with environment variables for flexibility and added a new filter for newspapers. Enhanced response parsing by including facets for related persons and organizations.
This commit is contained in:
ThomasTaroni 2025-07-03 23:33:12 +02:00
parent e5a6c59f7a
commit cf88959576

View file

@ -107,8 +107,14 @@ async def smd_research(search_query: str = "Bundesrat", date_from: str = "2024-0
{ {
"field": "datetime", "field": "datetime",
"value": [ "value": [
date_from, os.getenv('SWISSDOX_DATEFROM', '2020-12-31T23:00:00.000Z'),
date_to os.getenv('SWISSDOX_DATETO', '2023-12-31T22:59:00.000Z')
]
},
{
"field": "newspaper",
"value": [
os.getenv('SWISSDOX_NEWSPAPER', 'NZZ')
] ]
}, },
{ {
@ -134,6 +140,7 @@ async def smd_research(search_query: str = "Bundesrat", date_from: str = "2024-0
result = response.json() result = response.json()
articles = result.get("data", []) articles = result.get("data", [])
facets = result.get("facets", [])
tasks = [] tasks = []
for article in articles: for article in articles:
@ -142,7 +149,8 @@ async def smd_research(search_query: str = "Bundesrat", date_from: str = "2024-0
tasks.append(smd_detail_article(article_id)) tasks.append(smd_detail_article(article_id))
detailed_articles = await asyncio.gather(*tasks) detailed_articles = await asyncio.gather(*tasks)
return { return {
"original_result": result, "related_persons": facets.get("persons", []),
"related_organizations": facets.get("persons", []),
"detailed_articles": detailed_articles "detailed_articles": detailed_articles
} }
else: else: