Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (37 sloc) 1.37 KB
import urllib2
from BeautifulSoup import BeautifulStoneSoup
import csv
from datetime import datetime, date
"""Fetch XML on Capital Bikeshare station occupancy via cronjob, say every 15 minutes, and compile into a CSV for
analysis over time."""
html = urllib2.urlopen('').read()
soup = BeautifulStoneSoup(html)
lastupdate = soup.stations['lastupdate']
headers = ['id','name','terminalname','lat','long','installed','locked','temporary','nbbikes','nbemptydocks','nbemptydocks']
stations = []
now =
for s in soup.stations.findAll('station'):
row = [ now.strftime('%A'), now.year, now.month,, now.hour, now.minute, lastupdate,, s.find('name').string, \
s.terminalname.string,, s.long.string, \
s.locked.string, s.temporary.string, s.installed.string, \
s.nbbikes.string, s.nbemptydocks.string ]
stations.append( row )
fout = csv.writer( open('bikeshare.csv','a') )
for r in stations:
<stations lastUpdate="1311019547339" version="2.0">
<name>20th & Bell St</name>