Commit 08ddbdce authored by BODERE's avatar BODERE
Browse files

fix: atom template

parent 484d75d4
Pipeline #6524 passed with stage
in 46 seconds
...@@ -36,14 +36,14 @@ j2_templates = Jinja2Templates(directory=settings.templates_path) ...@@ -36,14 +36,14 @@ j2_templates = Jinja2Templates(directory=settings.templates_path)
# opensearch engines executed # opensearch engines executed
opensearch_engines = { opensearch_engines = {
"Opensearch Ifremer": # "Opensearch Ifremer":
IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=20.0), # IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=20.0),
"Opensearch Ifremer - timeout 1s": # "Opensearch Ifremer - timeout 1s":
IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=1.0), # IfremerOpensearchEngine(root_path='https://opensearch.ifremer.fr/granules.atom', timeout=1.0),
"Non-existent URL": # "Non-existent URL":
IfremerOpensearchEngine(root_path='https://toto.ifremer.fr/granules.atom', timeout=2.0), # IfremerOpensearchEngine(root_path='https://toto.ifremer.fr/granules.atom', timeout=2.0),
"JPL engine": "JPL engine":
JPLOpensearchEngine(root_path='https://cmr.earthdata.nasa.gov/opensearch/granules.atom', timeout=20.0) JPLOpensearchEngine(root_path='https://cmr.earthdata.nasa.gov/opensearch/granules.atom', timeout=30.0)
} }
......
...@@ -26,13 +26,25 @@ class OpensearchEngine: ...@@ -26,13 +26,25 @@ class OpensearchEngine:
self.timeout = timeout self.timeout = timeout
self._log = logging.getLogger(__name__) self._log = logging.getLogger(__name__)
def to_dict(self):
return {
"root_path": self.root_path,
"timeout": self.timeout
}
def __repr__(self):
return json.dumps(self.to_dict())
def __str__(self):
return repr(self)
async def request(self, params: OpensearchQueryParameters) -> Optional[OpensearchResponse]: async def request(self, params: OpensearchQueryParameters) -> Optional[OpensearchResponse]:
async def request_hook(request): async def request_hook(request):
self._log.debug("Request event hook: %s %s - Waiting for response", request.method, request.url) print("Request event hook: %s %s - Waiting for response", request.method, request.url)
async def response_hook(response): async def response_hook(response):
request = response.request request = response.request
self._log.debug(f"Response event hook: - Status %d", request.method, request.url, response.status_code) print(f"Response event hook: - Status %d", request.method, request.url, response.status_code)
url = self._build_search_url(params) url = self._build_search_url(params)
opensearch_response = OpensearchResponse(query=OpensearchQuery(params=params, url=url)) opensearch_response = OpensearchResponse(query=OpensearchQuery(params=params, url=url))
...@@ -43,10 +55,10 @@ class OpensearchEngine: ...@@ -43,10 +55,10 @@ class OpensearchEngine:
) as client: ) as client:
raw_response = await client.get(url=url, timeout=self.timeout) raw_response = await client.get(url=url, timeout=self.timeout)
opensearch_response.header, opensearch_response.entries = self._process_response(raw_response) opensearch_response.header, opensearch_response.entries = self._process_response(raw_response)
except httpx.ReadTimeout: except httpx.TimeoutException:
opensearch_response.errors.append("Timeout occurred") opensearch_response.errors.append("Timeout occurred")
except ValidationError as e: except ValidationError as e:
self._log.debug(e.json()) print(e.json())
opensearch_response.errors.append("Not a valid response") opensearch_response.errors.append("Not a valid response")
except Exception as e: except Exception as e:
msg = str(e).strip() msg = str(e).strip()
...@@ -135,31 +147,11 @@ class OpensearchAtomEngine(OpensearchEngine): ...@@ -135,31 +147,11 @@ class OpensearchAtomEngine(OpensearchEngine):
def get_text(self, elt: Element, name: str) -> Optional[str]: def get_text(self, elt: Element, name: str) -> Optional[str]:
sub_elt = elt.find(name, namespaces=self.namespaces) sub_elt = elt.find(name, namespaces=self.namespaces)
return sub_elt.text if sub_elt is not None else None
if name == "dc:date":
print('*' * 70)
print(Element.tostring(elt))
print(sub_elt)
#print(Element.tostring(sub_elt))
if sub_elt is None:
return None
return sub_elt.text
def get_children(self, elt: Element, name: str) -> List: def get_children(self, elt: Element, name: str) -> List:
return elt.findall(name, namespaces=self.namespaces) return elt.findall(name, namespaces=self.namespaces)
def to_dict(self):
return {
"root_path": self.root_path,
"timeout": self.timeout
}
def __repr__(self):
return json.dumps(self.to_dict())
def __str__(self):
return repr(self)
class IfremerOpensearchEngine(OpensearchAtomEngine): class IfremerOpensearchEngine(OpensearchAtomEngine):
"""Ifremer opensearch engine""" """Ifremer opensearch engine"""
...@@ -168,7 +160,6 @@ class IfremerOpensearchEngine(OpensearchAtomEngine): ...@@ -168,7 +160,6 @@ class IfremerOpensearchEngine(OpensearchAtomEngine):
entry = super()._parse_entry_metadata(entry_elt) entry = super()._parse_entry_metadata(entry_elt)
entry.dc_date = self.get_text(entry_elt, "dc:date") entry.dc_date = self.get_text(entry_elt, "dc:date")
entry.geobox = self.get_text(entry_elt, "georss:box") entry.geobox = self.get_text(entry_elt, "georss:box")
#entry.geobox_where = self.get_text(entry, "georss:geobox_where")
return entry return entry
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
{% if entry.dc_date %}<dc:date>{{entry.dc_date}}</dc:date>{% endif %} {% if entry.dc_date %}<dc:date>{{entry.dc_date}}</dc:date>{% endif %}
{% if entry.geobox %}<georss:box>{{entry.geobox}}</georss:box>{% endif %} {% if entry.geobox %}<georss:box>{{entry.geobox}}</georss:box>{% endif %}
{% for link in entry.links -%} {% for link in entry.links -%}
<link rel= "enclosure" href="{{link.href}}" /> <link {% if link.rel %}rel="{{link.rel}}"{% endif %} {% if link.title %}title="{{link.title}}"{% endif %} {% if link.type %}type="{{link.type}}"{% endif %} href="{{link.href}}" />
{% endfor %} {% endfor %}
</entry> </entry>
{% endfor %} {% endfor %}
......
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