Python包装器,用于从acuweather服务器获取天气数据。
accuweather的Python项目详细描述
天气预报
Python包装器,用于从acuweather服务器获取有限试用包的天气数据。在
API密钥
要生成API密钥,请转到https://developer.accuweather.com/user/register,注册后创建一个应用程序。在
如何使用软件包
importasyncioimportloggingfromaccuweatherimport(AccuWeather,ApiError,InvalidApiKeyError,InvalidCoordinatesError,RequestsExceededError,)fromaiohttpimportClientError,ClientSessionLATITUDE=52.0677904LONGITUDE=19.4795644LOCATION_KEY="268068"API_KEY="xxxxx"logging.basicConfig(level=logging.DEBUG)asyncdefmain():asyncwithClientSession()aswebsession:try:accuweather=AccuWeather(API_KEY,websession,latitude=LATITUDE,longitude=LONGITUDE)current_conditions=awaitaccuweather.async_get_current_conditions()forecast=awaitaccuweather.async_get_forecast(metric=True)except(ApiError,InvalidApiKeyError,InvalidCoordinatesError,ClientError,RequestsExceededError,)aserror: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}")loop=asyncio.get_event_loop()loop.run_until_complete(main())loop.close()
- 项目
标签: