Commit f85b4364 authored by BODERE's avatar BODERE
Browse files

feat: nasa engine

Refs: #3
parent 542fc7c5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from opensearx_ws.opensearch import IfremerOpensearchEngine
from opensearx_ws.opensearch import IfremerOpensearchEngine, NasaOpensearchEngine
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)
"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):
class OpensearchResponseEntryLink(BaseModel):
title: str
title: str = None
rel: str
type: str
type: str = None
href: str
......@@ -108,7 +108,12 @@ class OpensearchEngine:
def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict:
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]]:
......@@ -197,13 +202,12 @@ class NasaOpensearchEngine(OpensearchAtomEngine):
def _params_as_dict(self, params: OpensearchQueryParameters) -> Dict:
return {
"parentIdentifier": params.datasetId,
"startTime": params.timeStart,
"endTime": params.timeEnd,
"startTime": params.timeStart.strftime("%Y-%m-%dT%H:%M:%SZ"),
"endTime": params.timeEnd.strftime("%Y-%m-%dT%H:%M:%SZ"),
"spatial_type": "bbox",
"boundingBox": params.geoBox,
"numberOfResults": params.count,
"cursor": params.startPage,
"clientID": "opensearx"
"cursor": params.startPage + 1
}
def _parse_entry_metadata(self, entry: Element) -> OpensearchResponseEntry:
......@@ -212,9 +216,9 @@ class NasaOpensearchEngine(OpensearchAtomEngine):
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")
# dc_date=self.get_text(entry, "dc:date"),
# geobox=self.get_text(entry, "georss:box"),
# 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