猫史档案馆


【Python作品分享】天气获取【作品秀】

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


【作品展示】

center_image

 

【作品介绍】

可获取程序未来喵的天气信息

 

【作品源代码】

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


回复

上一页1 页 / 共 1下一页
Full_MarkFull_Mark

你费不费 easygui 的那个输入框???

点赞0


评论


一个STUB用户_14302596一个STUB用户_14302596

喵喵喵的地址是什么呀

点赞0


评论