Skip to content

Commit 4d24a3d

Browse files
Feat: implement fetch_publications function to retrieve publication data from VCell API
1 parent 78c59ab commit 4d24a3d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

backend/app/services/vcelldb_service.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.schemas.vcelldb_schema import BiomodelRequestParams, SimulationRequestParams
66
from urllib.parse import urlencode, quote
77
from langfuse import observe
8+
from typing import List
89

910
VCELL_API_BASE_URL = "https://vcell.cam.uchc.edu/api/v0"
1011

@@ -313,3 +314,41 @@ async def fetch_biomodel_applications_files(biomodel_id: str) -> dict:
313314
"applications": applications_with_files,
314315
"total_applications": len(applications_with_files),
315316
}
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

Comments
 (0)