Wind Weather website: https://www.heweather.com/
After registration there will be a personal authentication key in the console
API Help Documentation: HTTPS://WWW.HEWEATHER.COM/DOCUMENTS/API/V5
#!/usr/bin/python#-*-coding:utf-8-*-#调用和风天气API查询当前天气信息 #2017/07/12import jsonimport urllib2import oscity= ' Beijing ' # keykey= ' your key ' city_name={' Beijing ': ' Beijing ', ' Shanghai ': ' Shanghai '}city_hname=city_name.get (city) after registering with wind weather Get current Weather information def Get_json (city): Url= ' https://free-api.heweather.com/v5/now?city= ' +city_hname+ ' &key= ' +key# print URL html=urllib2.urlopen (URL). Read () return html# print html# f=open (city_hname+ '. txt ', ' W ') # F.write (HTML) # F.close#get_json (city) #解析json数据 #data=open (city_hname+ '. txt '). ReadLine () Data=get_json (city) Hjson=json.loads ( Data) basic_status=hjson[' HeWeather5 '][0][' basic ']nowtq_status=hjson[' HeWeather5 '][0][' Now ' #print now#print now_ status[' cond ' [' TXT '].encode (' utf-8 ') #格式化输出城市信息def Basic (databasic): print ' country/city name: \t%s/%s '% (databasic[' cnty '). Encode (' Utf-8 '), databasic[' City '].encode (' Utf-8 ')) print ' Information update time: \t%s '% (databasic[' update '] [' Loc '].encode (' Utf-8 ') #basic (basic_status) #格式化输出当前天气信息def tqms (DATANOWTQ): print ' current outdoor temperature: \t%s degrees '% (datanowtq[' tmp '). Encode (' Utf-8 ')) #print ' body sense temperature: \t%s '% (datanowtq[' fl '].encode (' Utf-8 ')) print ' Weather description: \t%s '% (datanowtq[' cond ' [' TXT '] . Encode (' utf-8 ') print ' relative humidity (%): \ t ' + '%s%% '% (datanowtq[' hum '].encode (' Utf-8 ')) print ' Wind/Wind: \t%s/%s level '% (datanowtq[') Wind ' [' dir '].encode (' Utf-8 '), datanowtq[' wind ' [' SC '].encode (' Utf-8 ')) print ' visibility (km): \t%skm '% (datanowtq[' vis '). Encode (' Utf-8 ')) Basic (Basic_status) TQMS (nowtq_status)
Keng:
1. Use Print to format the output percent percent, with the following examples:
Print ' %d%% ' % 2,323%
Use Python to call and wind weather API to query current weather information