Skip to content

Commit

Permalink
deleted try-except in get_crossmatch_data and put it in htmx. also ch…
Browse files Browse the repository at this point in the history
…anged function name in htmx
  • Loading branch information
claudiomansillab committed Nov 22, 2024
1 parent 91b3d8f commit 42b86a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 4 additions & 7 deletions lightcurve/src/crossmatch_api/get_crossmatch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def get_alerce_data(ra, dec, radius):
"radius": radius
}

try:
# Make the GET request
response = requests.get(base_url, params=params)
return response.json() # Return the JSON response

except requests.RequestException as e:
return f"Error: {str(e)}"
# Make the GET request
response = requests.get(base_url, params=params)
return response.json() # Return the JSON response

12 changes: 8 additions & 4 deletions lightcurve/src/crossmatch_api/routes/htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from typing import Annotated
from fastapi import Query
import json
import requests

from core.services.object import get_object
from fastapi import APIRouter, Request, HTTPException
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, HTMLError
from ..result_handler import handle_error, handle_success
from ..get_crossmatch_data import get_alerce_data
router = APIRouter()
Expand All @@ -20,14 +21,17 @@
)

@router.get("/crossmatch/{oid}", response_class=HTMLResponse)
async def object_mag_app(
async def object_xmatch_app(
request: Request,
oid: str,
):

object = get_object(oid,session_factory = request.app.state.psql_session)

cross = get_alerce_data(object.meanra, object.meandec, 20)
try:
cross = get_alerce_data(object.meanra, object.meandec, 20)
except requests.RequestException as e:
return HTMLError(e)

'''
get_alerce_data returns a list with several dictionaries. The dict format is one key and then a value that is another dictionary.
Expand All @@ -42,7 +46,7 @@ async def object_mag_app(
cross_keys = []
for i in range(len(cross)):
cross_keys.append(next(iter(cross[i].keys())))

return templates.TemplateResponse(
name='crossmatch.html.jinja',
context={'request': request,
Expand Down

0 comments on commit 42b86a0

Please sign in to comment.