猫史档案馆


【Python作品分享】TodayFace天气【作品秀】

用户:ZetaOidZetaOid查看:1 回复:3 评论:1 创建时间:2022-10-22T18:38:34


【作品展示】

center_image

 

【作品介绍】

天气软件

以后会图形化

 

【作品源代码】

#Code by Zo1diser
import json
import requests as req

input_city = input('输入查询的城市(汉字)')
print('')
print('')
api = 'https://v0.yiketianqi.com/api?unescape=1&version=v91&appid=43656176&appsecret=I42og6Lm&ext=&cityid=&city='+input_city
#对api发送请求
get_weather = req.get(api)
#获取返回的城市天气的json
json_data = get_weather.text
#转换字典
weather_dic = json.loads(json_data)
try:
    print('国家',weather_dic['country'])
    print('城市名',weather_dic['city'])
    print('获取时间',weather_dic['update_time'])
    print('天气',weather_dic['data'][0]['wea_day'])
    print('空气质量指数', weather_dic['data'][0]['air_level'])
    print('最高温度', weather_dic['data'][0]['tem']+'°C')
    print('最低温度', weather_dic['data'][0]['tem2']+'°C')
    print('风速', weather_dic['data'][0]['win_speed'])
    print('月相', weather_dic['data'][0]['moonPhrase'])
except:
    print('出现错误!请检查输入内容')

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
一个STUB用户_14302596一个STUB用户_14302596

发一下喵喵喵的链接地址

点赞0


评论


ZetaOidZetaOid

ht删掉tps://v0删.掉yiketianqi.com/api?unescape=1&version删掉=v91&appid=4365617删掉6&appsecret=I4删掉2og6Lm&ext=&cityid=&city=

点赞0


评论


ZetaOidZetaOid

看置顶吧

 

点赞1


评论