Python 天气预报

来源:互联网 发布:2017最流行编程语言 编辑:程序博客网 时间:2024/06/02 04:53
# !/usr/bin/env python# coding=utf-8import httplibimport jsonhttpClient = Nonetry:    httpClient = httplib.HTTPConnection('api.map.baidu.com', 80, timeout=30)    httpClient.request('GET',                       '/telematics/v3/weather?location=%E6%AD%A6%E6%B1%89&output=json&ak=KPGX6sBfBZvz8NlDN5mXDNBF&callback=')    response = httpClient.getresponse()    s = json.loads(response.read());    print s["results"][0]["currentCity"]    print s["results"][0]["weather_data"][0]["date"]    print s["results"][0]["weather_data"][0]["weather"]    print s["results"][0]["weather_data"][0]["wind"]    print s["results"][0]["weather_data"][0]["temperature"]except Exception, e:    print efinally:    if httpClient:        httpClient.close()/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/wangms/PycharmProjects/Python/weather/weather.py武汉周五 08月04日 (实时:33℃)阵雨转多云无持续风向微风35 ~ 27℃Process finished with exit code 0

原创粉丝点击