[python]代码库
import time
import requests
import easygui
def getToday(cityName):
url = 'http://wthrcdn.etouch.cn/weather_mini?city=' + cityName
response = requests.get(url)
weatherDict = response.json()
if weatherDict['desc'] == 'OK':
# 获取城市名
global city, wendu, month, forecast
city = weatherDict['data']['city']
# 获取当前温度
wendu = weatherDict['data']['wendu'] + '℃ '
# 获取月份
month = time.strftime()
forecast = weatherDict['data']['forecast']
# 获取日期
global date, type, high, low
date = month + '月' + forecast[0]['date']
# 获取天气类型
type = forecast[0]['type']
# 获取最高温度
high = forecast[0]['high']
# 获取最低温度
low = forecast[0]['low']
else:
print('你输入的城市是错误的')
cityName = easygui.enterbox('请输入要查询的中国城市', title='city')
getToday(cityName)
print('城市:' + city)
print('日期:' + date)
print('天气:' + type)
print('最' + high)
print('最' + low)
[代码运行效果截图]
[源代码打包下载]
中级程序员
by: mikeKil 发表于:2022-01-03 10:33:43 顶(0) | 踩(0) 回复
抄我的?
网友回复
回复高嘉易 : 没有啊???
顶(0) 踩(0) 2022-01-19 10:08:26
回复评论