Commit f85b4364 authored by BODERE's avatar BODERE
Browse files

feat: nasa engine

Refs: #3
parent 542fc7c5
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from opensearx_ws.opensearch import IfremerOpensearchEngine from opensearx_ws.opensearch import IfremerOpensearchEngine, NasaOpensearchEngine
opensearch_engines = { opensearch_engines = {
"Ifremer": IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=30.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), "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) "NotExistingURL": IfremerOpensearchEngine(root_path='https://toto.ifremer.fr/granules.atom', timeout=2.0),
"NasaURL": NasaOpensearchEngine(root_path='https://cmr.earthdata.nasa.gov/opensearch/granules.atom', timeout=30.0)
} }
...@@ -30,9 +30,9 @@ class OpensearchQueryParameters(BaseModel): ...@@ -30,9 +30,9 @@ class OpensearchQueryParameters(BaseModel):
class OpensearchResponseEntryLink(BaseModel): class OpensearchResponseEntryLink(BaseModel):
title: str title: str = None
rel: str rel: str
type: str type: str = None
href: str href: str
...@@ -108,7 +108,12 @@ class OpensearchEngine: ...@@ -108,7 +108,12 @@ class OpensearchEngine:
def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict: def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict:
return { return {
"datasetId": params.datasetId "datasetId": params.datasetId,
"timeStart": params.timeStart.strftime("%Y-%m-%dT%H:%M:%SZ"),
"timeEnd": params.timeEnd.strftime("%Y-%m-%dT%H:%M:%SZ"),
"geoBox": params.geoBox,
"count": params.count,
"startPage": params.startPage
} }
def _process_response(self, http_response: Response) -> Tuple[OpensearchResponseHeader, List[OpensearchResponseEntry]]: def _process_response(self, http_response: Response) -> Tuple[OpensearchResponseHeader, List[OpensearchResponseEntry]]:
...@@ -197,13 +202,12 @@ class NasaOpensearchEngine(OpensearchAtomEngine): ...@@ -197,13 +202,12 @@ class NasaOpensearchEngine(OpensearchAtomEngine):
def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict: def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict:
return { return {
"parentIdentifier": params.datasetId, "parentIdentifier": params.datasetId,
"startTime": params.timeStart, "startTime": params.timeStart.strftime("%Y-%m-%dT%H:%M:%SZ"),
"endTime": params.timeEnd, "endTime": params.timeEnd.strftime("%Y-%m-%dT%H:%M:%SZ"),
"spatial_type": "bbox", "spatial_type": "bbox",
"boundingBox": params.geoBox, "boundingBox": params.geoBox,
"numberOfResults": params.count, "numberOfResults": params.count,
"cursor": params.startPage, "cursor": params.startPage + 1
"clientID": "opensearx"
} }
def _parse_entry_metadata(self, entry: Element) -> OpensearchResponseEntry: def _parse_entry_metadata(self, entry: Element) -> OpensearchResponseEntry:
...@@ -212,9 +216,9 @@ class NasaOpensearchEngine(OpensearchAtomEngine): ...@@ -212,9 +216,9 @@ class NasaOpensearchEngine(OpensearchAtomEngine):
title=self.get_text(entry, "feed:title"), title=self.get_text(entry, "feed:title"),
updated=self.get_text(entry, "feed:updated"), updated=self.get_text(entry, "feed:updated"),
summary=self.get_text(entry, "feed:summary"), summary=self.get_text(entry, "feed:summary"),
dc_date=self.get_text(entry, "dc:date"), # dc_date=self.get_text(entry, "dc:date"),
geobox=self.get_text(entry, "georss:box"), # geobox=self.get_text(entry, "georss:box"),
geobox_where=self.get_text(entry, "geobox_where") # geobox_where=self.get_text(entry, "geobox_where")
) )
......
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