-
Notifications
You must be signed in to change notification settings - Fork 8
added historical module #5
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| '''Retrieve Historical Air Quality''' | ||
| from datetime import date as date_, datetime | ||
| from typing import Callable, Coroutine, Optional, Union | ||
|
|
||
|
|
||
| class Historical: | ||
| ''' | ||
| Class to retrieve historical air quality by zip code or by latitude and | ||
| longitude. | ||
| ''' | ||
| def __init__(self, request: Callable[..., Coroutine]) -> None: | ||
| self._request = request | ||
|
|
||
| async def zipCode( | ||
| self, | ||
| zipCode: str, | ||
| *, | ||
| date: Optional[Union[date_, datetime, str]] = None, | ||
| distance: Optional[int] = None | ||
| ) -> list: | ||
| '''Request current observation for zip code''' | ||
| params: dict = dict(zipCode=zipCode) | ||
| '''Airnow needs T00-0000 appended to the date parameter for historical calls''' | ||
| if date and isinstance(date, str): | ||
| y, m, d = date.split('-') | ||
| params['date'] = date_(int(y), int(m), int(d)).isoformat() + "T00-0000" | ||
| elif date and isinstance(date, datetime): | ||
| params['date'] = date.date().isoformat() + "T00-0000" | ||
| elif date and isinstance(date, date_): | ||
| params['date'] = date.isoformat() + "T00-0000" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is actually an odd form of extended ISO 8601 timestamp where the I probably should have done something similar originally in the Forecast module, although interestingly the Forecast API endpoint does not like the |
||
| if distance: | ||
| params['distance'] = distance | ||
|
|
||
| return await self._request( | ||
| 'aq/observation/zipCode/historical', | ||
| params=params | ||
| ) | ||
|
|
||
| async def latLong( | ||
| self, | ||
| latitude: Optional[Union[float, str]] = None, | ||
| longitude: Optional[Union[float, str]] = None, | ||
| *, | ||
| date: Optional[Union[date_, datetime, str]] = None, | ||
| distance: Optional[int] = None, | ||
| ) -> None: | ||
| '''Request current observation for latitude/longitude''' | ||
| params: dict = dict( | ||
| latitude=str(latitude), | ||
| longitude=str(longitude), | ||
| ) | ||
| if date and isinstance(date, str): | ||
| y, m, d = date.split('-') | ||
| params['date'] = date_(int(y), int(m), int(d)).isoformat() + "T00-0000" | ||
| elif date and isinstance(date, datetime): | ||
| params['date'] = date.date().isoformat() + "T00-0000" | ||
| elif date and isinstance(date, date_): | ||
| params['date'] = date.isoformat() + "T00-0000" | ||
| if distance: | ||
| params['distance'] = distance | ||
|
|
||
| return await self._request( | ||
| 'aq/observation/latLong/historical', | ||
| params=params | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think even though the API allows a call with no date and returns an empty set of observations, it makes more sense for a historical API to make this required and do our own check for presence in the code. This seems to work a bit differently than the forecast which defaults to today if the parameter isn't sent.