Python wrapper for getting weather data from AccuWeather API.
Project description
accuweather
Python wrapper for getting weather data from AccuWeather API.
API key
To generate API key go to https://developer.accuweather.com/user/register and after registration create an app.
How to use package
"""Example of usage."""
import asyncio
import logging
from aiohttp import ClientError, ClientSession
from accuweather import (
AccuWeather,
ApiError,
InvalidApiKeyError,
InvalidCoordinatesError,
RequestsExceededError,
)
LATITUDE = 52.0677904
LONGITUDE = 19.4795644
API_KEY = "xxxxx"
logging.basicConfig(level=logging.DEBUG)
async def main():
"""Run main function."""
async with ClientSession() as websession:
try:
accuweather = AccuWeather(
API_KEY,
websession,
latitude=LATITUDE,
longitude=LONGITUDE,
language="pl",
)
current_conditions = await accuweather.async_get_current_conditions()
forecast_daily = await accuweather.async_get_daily_forecast(
days=5, metric=True
)
forecast_hourly = await accuweather.async_get_hourly_forecast(
hours=12, metric=True
)
except (
ApiError,
InvalidApiKeyError,
InvalidCoordinatesError,
ClientError,
RequestsExceededError,
) as error:
print(f"Error: {error}")
else:
print(f"Location: {accuweather.location_name} ({accuweather.location_key})")
print(f"Requests remaining: {accuweather.requests_remaining}")
print(f"Current: {current_conditions}")
print(f"Forecast: {forecast_daily}")
print(f"Forecast hourly: {forecast_hourly}")
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
accuweather-2.1.1.tar.gz
(13.0 kB
view hashes)
Built Distribution
Close
Hashes for accuweather-2.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d6ce2973dd8fa740f8e64eabcb5c07d86e0065a60227817621036eed0385d6 |
|
MD5 | 2390355f09a1289190aac1d3d39ae38d |
|
BLAKE2b-256 | c95b80deab693eebc0ca162f1dca0cf8b52b61701ae77994f705b0252493217c |