发表在 P.R.G! 08-24 16:46:33
#coding=utf-8
import requests
import re
import json
while True:
bb = input("查询哪里的天气?:")
if bb == '':
print ('请输入城市名!')
continue
c = requests.get ('http://wthrcdn.etouch.cn/weather_mini?city='+bb)
if c.text == '{"desc":"invilad-citykey","status":1002}':
print ('请输入正确的城市名!')
continue
x = json.loads(c.text)
x2 = x['data']
x3 = x2 ['forecast']
a = x3[0]
a1 = x3[1]
a2 = x3[2]
a3 = x3[3]
a4 = x3[4]
print ()
print ('今日',bb,x2['ganmao'])
print ('今日',bb,'气温',x2['wendu'])
print ()
print (a['fengxiang'],a['fengli'],a['high'],a['type'],a['low'],a['date'])
print (a1['fengxiang'],a1['fengli'],a1['high'],a1['type'],a1['low'],a1['date'])
print (a2['fengxiang'],a2['fengli'],a2['high'],a2['type'],a2['low'],a2['date'])
print (a3['fengxiang'],a3['fengli'],a3['high'],a3['type'],a3['low'],a3['date'])
print (a4['fengxiang'],a4['fengli'],a4['high'],a4['type'],a4['low'],a4['date'])
print ()
Python3 环境
终端天气 -- the terminal weather reporter
至少发个C吗!
哇 学习了