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

Add hourly forecast #57

Merged
merged 11 commits into from
Aug 24, 2022
Merged

Add hourly forecast #57

merged 11 commits into from
Aug 24, 2022

Conversation

Geno1
Copy link
Contributor

@Geno1 Geno1 commented Jul 24, 2022

Added a method to pull the hourly forecast data from Accuweather.

@bieniu bieniu changed the title Hourly forecast Add hourly forecast Jul 31, 2022
@bieniu
Copy link
Owner

bieniu commented Jul 31, 2022

Please format code with Black.

@bieniu bieniu added the enhancement New feature or request label Jul 31, 2022
Copy link
Owner

@bieniu bieniu left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I have a few minor comments. Please also add tests for the new method and update example.py and README.md files.

accuweather/__init__.py Show resolved Hide resolved
if not location_key:
if not self._valid_coordinates(latitude, longitude):
raise InvalidCoordinatesError("Your coordinates are invalid")

Copy link
Owner

Choose a reason for hiding this comment

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

Please do not remove this empty line.

accuweather/__init__.py Show resolved Hide resolved
@@ -119,15 +116,22 @@ def _parse_forecast(data: dict, to_remove: tuple) -> list:
day[f"{temp}Min"] = day[temp]["Minimum"]
day[f"{temp}Max"] = day[temp]["Maximum"]
day.pop(temp)

Copy link
Owner

Choose a reason for hiding this comment

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

Please do not remove this empty line.

return False

@staticmethod
def _valid_api_key(api_key: str) -> bool:
"""Return True if API key is valid."""
if isinstance(api_key, str) and len(api_key) == 32:
return True

Copy link
Owner

Choose a reason for hiding this comment

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

Please do not remove this empty line.

@@ -146,6 +150,10 @@ async def _async_get_data(self, url: str) -> dict[str, Any]:
data = await resp.json()
if resp.headers["RateLimit-Remaining"].isdigit():
self._requests_remaining = int(resp.headers["RateLimit-Remaining"])

# nasty hack to account for different data structure returned by hourly forecast API call
Copy link
Owner

Choose a reason for hiding this comment

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

I really don't like this. Please change return type for this method to Any and use something like this:

        if "hourly" in url:
            return data

        return data if isinstance(data, dict) else data[0]

@bieniu
Copy link
Owner

bieniu commented Aug 21, 2022

@Geno1 Do you plan to continue this PR?

@Geno1
Copy link
Contributor Author

Geno1 commented Aug 21, 2022 via email

@bieniu bieniu changed the base branch from master to hourly August 24, 2022 13:35
@bieniu bieniu merged commit 964bbcb into bieniu:hourly Aug 24, 2022
@bieniu
Copy link
Owner

bieniu commented Aug 24, 2022

@Geno1 Thanks for your contributions 👍

bieniu added a commit that referenced this pull request Aug 24, 2022
* Add hourly forecast (#57)

* Add API call for retrieving 12-hour hourly forecast data

* Create main.py

* Delete main.py

Remove test code

* Silence black

* More black complaints "fixed"

* Change data structure returned for hourly forecast

* More complaints silenced

* Remove unnecessary import

* Remove unnecessary import

* Revert "Remove unnecessary import"

This reverts commit e127e7c.

* Fix return type once more

* Format

* Fix _async_get_data return

* Fix forecast

* Update example and readme

* Add tests

* Update example and readme

* Improve typing

Co-authored-by: Geno1 <genone@genone.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants