[ Content | View menu ]

Making Things Talk … Python Style

Written on February 14, 2009

Finally getting around to reading Making Thing Talk, and can’t help but think in Python rather than PHP (publish via Django and you’re set). One of the early labs deals with displaying pseudo-realtime air quality readings (AQI) on a voltmeter. They go through a couple of pages of PHP to do a scrape — I couldn’t help but throw down the following (reminder — Python rulz!):

data = urllib.urlopen(‘http://airnow.gov/index.cfm?action=airnow.showlocal&cityid=164′).read()
‘<AQI: %s>’ % re.findall(‘<table .*?AQI observed at (.*?):<.*?<b>(.*?)</b>.*</table>’, data, re.S|re.S)[0][1]

Filed in: Crib Search,Geek Stuff.

No Comments

Write comment - TrackBack - RSS Comments

Write comment