气象地下包装材料
WunderWeather的Python项目详细描述
无论您已经是一个用户并希望对文档进行刷新,还是第一次评估包,您都来到了正确的位置。那么,你想进一步了解什么?
Introduction
wunderweather试图公开由Weather Underground提供的数据,这种方式易于使用,并且很容易将天气数据快速输入到应用程序中,而无需处理所有细节。
About the Wunderground API
wunderground api提供了名为data features的不同端点,当提供了适当的参数时,这些端点将返回描述正在查询的特性的许多数据点。
About the WunderWeather API
Wunderweather的构建是为了以统一的方式公开Wunderground提供的数据。对于应用它的某些数据特性,创建包装器类以规范化返回的数据并提供对该数据的易访问性。
- 在开发Wunderweather时,需要记住以下几个关键概念。如果你想贡献,请记住这些想法。
- 在Wunderground如此慷慨地提供的数百个数据点中,通过数据功能特定的包装,暴露到更常用/流行的数据点(如温度和日期)的快捷方式。
- 对于历史数据功能,Wunderground使用3个键而不是Wunderweather中提取的键来公开平均温度数据点
w地下:
>>> response["history"]["daily_summary"]["meantempi"]
wunderweather:
>>> response.temp_f
- 规范化要公开的数据点名称。
- WundergroundAPI在提供无休止的天气数据方面做得很好,但不幸的是,不同功能中的类似数据点有不同的名称。经常出现这种情况的一个例子是英制(I)和公制(M)以及它们各自的温度华氏度(F)和摄氏度(C)标识符。
示例数据点:
- 温度i vs温度f
- 温度与温度
Installation
pip install WunderWeather
Code Examples
以下代码片段是从数据功能响应中提取数据的示例。一些示例是在前面的示例的基础上构建的(为了避免重复),但是应该正确地记录为continuation from NNN example。
警告
Wunderweather包只与Python3兼容。
注意
因为requests package太棒了,我们将在下面的示例中使用它来发出请求。我们用它在我们的包裹里提出要求,你也应该这样做!
Weather Underground Example
不使用请求
在地下文档中列出的示例
importurllib2importjsonf=urllib2.urlopen('http://api.wunderground.com/api/<YOUR_API_KEY>/geolookup/conditions/q/IA/Cedar_Rapids.json')json_string=f.read()parsed_json=json.loads(json_string)location=parsed_json['location']['city']temp_f=parsed_json['current_observation']['temp_f']print"Current temperature in %s is: %s"%(location,temp_f)f.close()
使用请求
在Wunderground文档中列出的示例已转换为使用请求
importrequests# learn more: https://python.org/pypi/requestsresponse=requests.get('http://api.wunderground.com/api/<YOUR_API_KEY>/geolookup/conditions/q/MA/Boston.json').json()location=response['location']['city']temp_f=response['current_observation']['temp_f']print("Current Temperature in %s is: %s"%(location,temp_f))
使用Wunderweather
wunderground文档中列出的示例已转换为使用wunderweather
fromwunderimportweatherextractor=weather.Extract(api_key)[location,current]=extractor.features("MA/Boston",(('geolookup',''),('now','')))print("Current Temperature in %s is: %s"%(location.data.city,current.temp_f))
在上面的示例中,请注意如何使用点符号从功能中提取数据点,无论是否存在特定于功能的包装类,以便在调用应用程序中提供统一的外观。从包装类引用快捷方式或直接访问数据时,外观相同。编写本文档时,geolookup没有包装器,因此从该功能提取的所有数据都必须使用WeatherBase.data成员才能使用点符号。。
Additional Examples
FrompprintimportpprintimportarrowFromWunderWeatherimportweather# setupapi_key="your api key"location='MA/Boston'extractor=weather.Extract(api_key)# alertsresponse=extractor.alerts(location)pprint(response.data)# astronomyresponse=extractor.astronomy(location)pprint(response.data)# geolookupresponse=extractor.geolookup(location)pprint(response.data)# historydate=arrow.get("20170601","YYYYMMDD")response=extractor.date(location,date.format('YYYYMMDD'))pprint(response.data)# addl date detailforobservationinresponse.observations:print("Date:",observation.date_pretty)print("Temp:",observation.temp_f)
Contributors
感谢您查看此部分,并表示有兴趣使此包更好。以下是可以使用抛光或扩展的兴趣点。与往常一样,如果您看到数据特性中的数据点可以使用抽象级别,那么只需添加一个包装类(如果尚未定义),并向该类添加一个属性成员,以便在特性之间提供快捷方式或规范化的外部名称。
TODOs
- 当前飓风
- Rawtide和潮汐
- 基于*的小时功能
几个数据特征只存在于通用的WebEnraseBasic类中,因此它们的数据是使用数据成员访问的。很可能有理由为这些特性创建包装器。目前的飓风似乎最需要一个包装。但是,下面列出了一些可能从抽象中受益的其他内容。 - 当然,还有文档、文档和更多文档的帮助。