Skip to content

Commit

Permalink
set OSCAR/Surface as default, catch station idDoesNotExist errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Sep 25, 2024
1 parent 6a03e19 commit ebda031
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pyoscar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class OSCARClient:
"""OSCAR client API"""

def __init__(self, env: str = 'depl', api_token: str = None,
def __init__(self, env: str = 'prod', api_token: str = None,
timeout: int = 30):
"""
Initialize an OSCAR Client.
Expand All @@ -57,7 +57,7 @@ def __init__(self, env: str = 'depl', api_token: str = None,
"""

self.env = env
"""OSCAR environment (depl or prod)"""
"""OSCAR environment (prod or depl)"""

self.api_url = None
"""URL to OSCAR API"""
Expand All @@ -81,11 +81,12 @@ def __init__(self, env: str = 'depl', api_token: str = None,

LOGGER.debug('Setting URL')
if self.env == 'prod':
self.api_url = 'https://oscar.wmo.int/surface/rest/api'
self.harvest_url = 'https://oscar.wmo.int/oai/provider'
host = 'oscar.wmo.int'
else:
self.api_url = 'https://oscardepl.wmo.int/surface/rest/api'
self.harvest_url = 'https://oscardepl.wmo.int/oai/provider'
host = 'oscardepl.wmo.int'

self.api_url = f'https://{host}/surface/rest/api'
self.harvest_url = f'https://{host}/oai/provider'

if self.api_token is not None:
self.headers['X-WMO-WMDR-Token'] = self.api_token
Expand Down Expand Up @@ -250,6 +251,11 @@ def get_station_report_summary(self, station: Union[dict, etree.Element]) -> dic
summary['wmo_region'] = station['wmoRaId']

else: # etree.Element
error = get_xpath(station, '//oai:error')
if error is not None:
LOGGER.warning(error)
return {}

station_name = get_xpath(
station, '//wmdr:ObservingFacility/gml:name')

Expand Down Expand Up @@ -415,6 +421,7 @@ def get_xpath(element: etree.Element, xpath: str,
namespaces = {
'wmdr': 'http://def.wmo.int/wmdr/2017',
'gml': 'http://www.opengis.net/gml/3.2',
'oai': 'http://www.openarchives.org/OAI/2.0/',
'xlink': 'http://www.w3.org/1999/xlink'
}

Expand Down

0 comments on commit ebda031

Please sign in to comment.