jiang-1 发表于 2016-4-17 22:25:28

我要看

粪球2005 发表于 2016-4-18 10:36:50

1

米格29 发表于 2016-5-6 13:20:28

想看看

whuer_py 发表于 2016-5-6 16:59:20

这么牛逼啊

偏爱丨小汐 发表于 2016-5-7 10:24:04

赞赞的

ahhqwllx 发表于 2016-5-8 00:01:17

来学系一哈

艾斯不知火 发表于 2016-5-8 21:49:24

很好太喜欢了

艾斯不知火 发表于 2016-5-8 22:58:26

import urllib.request
import gzip
import json
print('------天气查询------')
def get_weather_data() :
    city_name = input('请输入要查询的城市名称:')
    url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(city_name)
    url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100'
    #网址1只需要输入城市名,网址2需要输入城市代码
    #print(url1)
    weather_data = urllib.request.urlopen(url1).read()
    #读取网页数据
    weather_data = gzip.decompress(weather_data).decode('utf-8')
    #解压网页数据
    weather_dict = json.loads(weather_data)
    #将json数据转换为dict数据
    return weather_dict

def show_weather(weather_data):
    weather_dict = weather_data
    #将json数据转换为dict数据
    if weather_dict.get('desc') == 'invilad-citykey':
      print('你输入的城市名有误,或者天气中心未收录你所在城市')
    elif weather_dict.get('desc') =='OK':
      forecast = weather_dict.get('data').get('forecast')

      

      
      print('城市:',weather_dict.get('data').get('city'))
      print('温度:',weather_dict.get('data').get('wendu')+'℃ ')
      print('感冒:',weather_dict.get('data').get('ganmao'))
      print('风向:',forecast.get('fengxiang'))
      print('风级:',forecast.get('fengli'))
      print('高温:',forecast.get('high'))
      print('低温:',forecast.get('low'))
      print('天气:',forecast.get('type'))
      print('日期:',forecast.get('date'))
      print('*******************************')
      four_day_forecast =input('是否要显示未来四天天气,是/否:')
      if four_day_forecast == '是' or 'Y' or 'y':
            for i in range(1,5):
                print('日期:',forecast.get('date'))
                print('风向:',forecast.get('fengxiang'))
                print('风级:',forecast.get('fengli'))
                print('高温:',forecast.get('high'))
                print('低温:',forecast.get('low'))
                print('天气:',forecast.get('type'))
                print('--------------------------')
    print('***********************************')
    end = input('是否要退出呢,是/否:')

show_weather(get_weather_data())

在最后加一句 end = input('是否要退出呢,是/否:') 不然会闪退

爱谁谁91 发表于 2016-5-9 11:37:44

学习学习

lincox 发表于 2016-5-9 14:32:11

谢谢楼主的源码。

壽哥 发表于 2016-5-10 19:54:15

这个可以有啊,我喜欢查询天气

meo 发表于 2016-5-11 05:52:10

谢谢 拿来看看

天才少年李狗蛋 发表于 2016-5-12 09:15:30

{:10_277:}

Barryhan 发表于 2016-5-12 10:47:43

参考参考

dick2016 发表于 2016-5-12 10:53:03

666666

yearlz 发表于 2016-5-12 13:30:56

很强大啊···

lanbingwxf 发表于 2016-5-12 16:15:00


好郁闷 发表于 2016-5-12 17:14:42

学习一下吧~啥都不懂~~呜呜

风语如歌 发表于 2016-5-13 08:46:09

学习学习

celestewang 发表于 2016-5-13 13:37:09

要是能预测就更好了
页: 20 21 22 23 24 25 26 27 28 29 [30] 31 32 33 34 35 36 37 38 39
查看完整版本: 新人天气查询程序,绝对可用