Qpython: Read PM2.5 on the Internet

Source: Internet
Author: User

Reference Http://pm25.in/api_doc

pm2_5.py source code is as follows

#-*-Coding:utf8-*-#qpy: Console#qpy:2import urllibimport urllib2import jsonimport androidhelperimport sysreload (SYS) Sys.setdefaultencoding (' utf-8 ') Droid = Androidhelper. Android () city = ' guangzhou ' token = ' x ' url = u ' http://www.pm25.in/api/querys/pm2_5.json?city=%s&token=%s ' U2 = Urllib2.urlopen (url% (city, token)) data = U2.read () u2.close () print type (data) print Dataprint '-' *60alist = []i = 0n = Le N (data) while I < N:begin = Data.find (' {', i) end = Data.find ('} ', begin) if begin < End:alist.append (data[begin:end+1]) else:break i = end+2blist = []if len (alist) >2:for d in alist:j = json. Jsondecoder (). Decode (d) #print type (j) line = str (j["Position_name"]) + ' +str (j["Pm2_5"]) + "+ str (j[" Qualit    Y "]) Print line blist.append (line) # Droid.dialogcreatealert (U ' select Location ') droid.dialogsetitems (blist) Droid.dialogshow () # Get the selected item result = Droid.dialoggetresponse (). Result Droid.dialOgdismiss () If ' item ' in result:target = alist[result[' item '] Print target 


Qpython: Read PM2.5 on the Internet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.