After I posted the UV Index demo, a kind person pointed me to some live air pollution data helpfully supplied by the government of Hong Kong. It was a very straightforward matter – using the awesome feedparser Python module – to extract the air pollution level for Central Hong Kong, and convert that to a color which is then displayed on the Light:
#!/usr/bin/python # import feedparser import sys, urllib2, string d = feedparser.parse('http://data.one.gov.hk/dataset/2/en') for entry in d.entries: parts = string.split(entry.title, ' : ') if parts[0] == u'Central': pollution = parts[2] colorval = 0x808080 # Map the value based on the value provided in the feed if (pollution == u'High'): colorval = 0xFFFF80 if (pollution == u'Very High'): colorval = 0x80FF80 if (pollution == u'Low'): colorval = 0xFF8080 colorstr = "http://localhost/cgi-bin/ajaxcolor?color=0x%6x" % colorval print colorstr e = urllib2.urlopen(colorstr)