用户:⃞𝓗⃞𝓮⃞𝓵⃞𝓵⃞𝓸查看:4 回复:2 评论:4 创建时间:2022-09-18T13:55:56
【作品展示】

【作品介绍】
可获取程序未来喵的天气信息
【作品源代码】
import requests
from bs4 import BeautifulSoup
import ctypes as Loader
import json
def GetCityWeather():
print('请输入你要查询的城市:')
response = requests.get('http://wthrcdn.etouch.cn/weather_mini?city='+input())
response.encoding = 'utf-8'
jsonWeather = json.loads(response.text)
if(jsonWeather['desc'] == 'OK'):
WeatherList = jsonWeather['data']['forecast']
outPut = ''
for i in range(0, len(WeatherList)):
CurrentWeather = WeatherList[i]
JsonCurrentWeather = json.loads(json.dumps(CurrentWeather))
outPut += ' ' + JsonCurrentWeather['date'] + ': ' + JsonCurrentWeather['type'] + ' ' \
+ '最高温:' + JsonCurrentWeather['high'].replace('高温 ', '') \
+ ' ~ ' \
+ '最低温:' + JsonCurrentWeather['low'].replace('低温 ', '') \
+ '\r\n'
pass
print('\r\n查询到的天气数据 =======>\r\n' + outPut)
else:
print('查询返回数据错误,请纠正后查询.')
print('Get City Weather 1.0.0 - (Only Support City Name)')
GetCityWeather()
while(True):
print('是否要继续查询(N/Y)')
if input().lower() == "y":
GetCityWeather()
if input().lower() == "n":
break
if input().lower() != "n" or input().lower() != "y":
print('未知的选项分支.')
continue
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn