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( '%m' ) |
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) |