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

Conversation

david-i-berry
Copy link
Contributor

  • Fallback to REST API when either error accessing through OAI-PMH or when record deleted
  • Additional error handling / catching added

- Fallback to REST API when either error accessing through OAI-PMH or when record deleted
- Additional error handling / catching added
@@ -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 "error" in str(response.content) or 'status="deleted"' in str(response.content):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if any(s in response.text for s in ['error', 'deleted']):

@@ -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 "error" in str(response.content) or 'status="deleted"' in str(response.content):
# WSI not found via OAPI route, note this only works for primary WSI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            # WSI not found via OAI-PMH 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}'
            response = requests.get(request, headers=self.headers)
            if response.status_code == 404:
                LOGGER.warning(f'identifier {identifier} not found via REST API')
                return {}

optimise checking of response text.
Removal of hard coded API URL.
@tomkralidis tomkralidis merged commit 1764cac into wmo-cop:master Jan 24, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants