|
5 | 5 | from app.schemas.vcelldb_schema import BiomodelRequestParams, SimulationRequestParams |
6 | 6 | from urllib.parse import urlencode, quote |
7 | 7 | from langfuse import observe |
| 8 | +from typing import List |
8 | 9 |
|
9 | 10 | VCELL_API_BASE_URL = "https://vcell.cam.uchc.edu/api/v0" |
10 | 11 |
|
@@ -313,3 +314,41 @@ async def fetch_biomodel_applications_files(biomodel_id: str) -> dict: |
313 | 314 | "applications": applications_with_files, |
314 | 315 | "total_applications": len(applications_with_files), |
315 | 316 | } |
| 317 | + |
| 318 | + |
| 319 | +@observe(name="FETCH_PUBLICATIONS") |
| 320 | +async def fetch_publications() -> List[dict]: |
| 321 | + """ |
| 322 | + Fetch a list of publications from the VCell API. |
| 323 | +
|
| 324 | + Returns: |
| 325 | + List[dict]: A list of publication dictionaries. |
| 326 | + """ |
| 327 | + url = f"{VCELL_API_BASE_URL}/publication?submitLow=&submitHigh=&startRow=1&maxRows=1000&hasData=all&waiting=on&queued=on&dispatched=on&running=on" |
| 328 | + |
| 329 | + logger.info(f"Fetching publications from URL: {url}") |
| 330 | + |
| 331 | + try: |
| 332 | + async with httpx.AsyncClient() as client: |
| 333 | + response = await client.get(url) |
| 334 | + response.raise_for_status() |
| 335 | + publications = response.json() |
| 336 | + |
| 337 | + # Ensure we return a list of dictionaries |
| 338 | + if isinstance(publications, list): |
| 339 | + logger.info(f"Successfully fetched {len(publications)} publications") |
| 340 | + return publications |
| 341 | + else: |
| 342 | + logger.warning(f"Unexpected response format: {type(publications)}") |
| 343 | + return [] |
| 344 | + |
| 345 | + except httpx.HTTPStatusError as e: |
| 346 | + logger.error(f"HTTP error fetching publications: {e.response.status_code} - {e.response.text}") |
| 347 | + raise e |
| 348 | + except httpx.RequestError as e: |
| 349 | + logger.error(f"Request error fetching publications: {str(e)}") |
| 350 | + raise e |
| 351 | + except Exception as e: |
| 352 | + logger.error(f"Unexpected error fetching publications: {str(e)}") |
| 353 | + raise e |
| 354 | + |
0 commit comments