Commit 542fc7c5 authored by BODERE's avatar BODERE
Browse files

fix: init merge response

parent ae703802
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from opensearx_ws.opensearch import IfremerOpenSearchEngine
from opensearx_ws.opensearch import IfremerOpensearchEngine
opensearch_engines = {
"Ifremer": IfremerOpenSearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=30.0),
"TimeoutFailed": IfremerOpenSearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=2.0),
"NotExistingURL": IfremerOpenSearchEngine(root_path='https://toto.ifremer.fr/granules.atom', timeout=2.0)
"Ifremer": IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=30.0),
"TimeoutFailed": IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=2.0),
"NotExistingURL": IfremerOpensearchEngine(root_path='https://toto.ifremer.fr/granules.atom', timeout=2.0)
}
......@@ -9,7 +9,7 @@ import uvicorn
from starlette.requests import Request
from opensearx_ws.config import opensearch_engines
from opensearx_ws.opensearch import OpensearchQueryParameters
from opensearx_ws.opensearch import OpensearchQueryParameters, merge_response
app = FastAPI()
......@@ -24,7 +24,7 @@ async def granule(params: OpensearchQueryParameters = Depends()):
# @see : https://docs.python.org/fr/3/library/asyncio-task.html#running-tasks-concurrently
tasks = [asyncio.create_task(engine.request(params)) for engine in opensearch_engines.values()]
responses = await asyncio.gather(*tasks)
# TODO merge responses
#return merge_response(responses, params)
return responses
......
......@@ -178,7 +178,7 @@ class OpensearchAtomEngine(OpensearchEngine):
return elt.findall(name, namespaces=self.namespaces)
class IfremerOpenSearchEngine(OpensearchAtomEngine):
class IfremerOpensearchEngine(OpensearchAtomEngine):
def _parse_entry_metadata(self, entry: Element) -> OpensearchResponseEntry:
return OpensearchResponseEntry(
......@@ -190,3 +190,33 @@ class IfremerOpenSearchEngine(OpensearchAtomEngine):
geobox=self.get_text(entry, "georss:box"),
geobox_where=self.get_text(entry, "geobox_where")
)
class NasaOpensearchEngine(OpensearchAtomEngine):
def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict:
return {
"parentIdentifier": params.datasetId,
"startTime": params.timeStart,
"endTime": params.timeEnd,
"spatial_type": "bbox",
"boundingBox": params.geoBox,
"numberOfResults": params.count,
"cursor": params.startPage,
"clientID": "opensearx"
}
def _parse_entry_metadata(self, entry: Element) -> OpensearchResponseEntry:
return OpensearchResponseEntry(
id=self.get_text(entry, "feed:id"),
title=self.get_text(entry, "feed:title"),
updated=self.get_text(entry, "feed:updated"),
summary=self.get_text(entry, "feed:summary"),
dc_date=self.get_text(entry, "dc:date"),
geobox=self.get_text(entry, "georss:box"),
geobox_where=self.get_text(entry, "geobox_where")
)
def merge_response(responses: List[OpensearchResponse], params: OpensearchQueryParameters) -> OpensearchResponse:
return responses[0]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment