Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to get_station_report #14

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pyoscar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,31 @@ def get_station_report(self, identifier: str, summary=False,
LOGGER.debug(f'Request: {response.url}')
LOGGER.debug(f'Response: {response.status_code}')

if any(s in response.text for s in ['error', 'deleted']):
# noqa WSI not found via OAPI route, note this only works for primary WSI
# Try REST API, note this is much slower
LOGGER.warning(f"Falling back to REST API for {identifier}")
request = f"{self.api_url}/wmd/download/{identifier}" # noqa
response = requests.get(request, headers=self.headers)
if response.status_code == 404:
return {}

response.raise_for_status()

if format_ == 'XML':
response = etree.fromstring(response.content)
try:
response = etree.fromstring(response.content)
except Exception as e:
raise e
else:
response = response.json()

if summary:
LOGGER.debug('Generating report summary')
return self.get_station_report_summary(response)
try:
return self.get_station_report_summary(response)
except Exception as e:
raise e
else:
return response

Expand Down
Loading