帮我写一个本地运行的查询深圳天气的接口
import requests
def get_shenzhen_weather():
url = 'http://wthrcdn.etouch.cn/weather_mini?city=深圳'
response = requests.get(url)
data = response.json()
if data['status'] == 1000:
weather_data = data['data']
city = weather_data['city']
temperature = weather_data['wendu']
weather = weather_data['forecast'][0]['type']
wind = weather_data['forecast'][0]['fengxiang']
return f"{city}的天气为:{weather},温度为:{temperature}℃,风向为:{wind}"
else:
return "获取天气信息失败"
if __name__ == '__main__':
print(get_shenzhen_weather())
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。