和风天气的天气预报,为个人开发者提供免费的天气预报数据。(有访问次数的限制)。
注册开发者账号
第一步,我们需要去注册一个开发者账号:
网址: https://id.heweather.com/login?redirect=https://console.heweather.com/my/service
阅读开发者文档
参考:https://dev.heweather.com/docs/getting-started/get-api-key
然后我们来看调用的示例代码:
没有 python 的。
分析其 api 接口文档:
给出一个 python 的示例:
# coding=utf-8
import requests
yburl = 'https://free-api.heweather.com/s6/weather/forecast'
cyurl = 'https://free-api.heweather.com/s6/weather/lifestyle'
value = {
'location': '广州',
'key': '1fb7bd7b7a224138b85e1d2f570b86a1',
'lang': 'zh'
}
ybreq = requests.get(yburl, params=value)
cyreq = requests.get(cyurl, params=value)
ybjs = ybreq.json()
cyjs = cyreq.json()
for i in range(2):
yb = ybjs['HeWeather6'][0]['daily_forecast']
cy = cyjs['HeWeather6'][0]['lifestyle'][1]
gj = cyjs['HeWeather6'][0]['lifestyle'][0]
d1 = u'广州' + ' ' + yb[i]['date'] + ' ' + yb[i]['cond_txt_d']
d2 = gj['txt'] + ' ' + cy['txt']
d3 = d1 + '\n' + d2
print(d3)
运行结果:
如果想实现更多的功能,可以参考
接入微信
接下来考虑接入微信通知。这样就可以及时带伞啦。😆
待续 …