Skip to content

Instantly share code, notes, and snippets.

@jimr
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimr/d0539876ff041da8926a to your computer and use it in GitHub Desktop.
Save jimr/d0539876ff041da8926a to your computer and use it in GitHub Desktop.
Get NextBike rental station numbers for Bath. I'm guessing about the time zone data for when the feed was updated (no docs that I can find).
import datetime
import sys
import urllib2
import xml.etree.ElementTree as ET
url = "https://nextbike.net/maps/nextbike-live.xml"
stations = sys.argv[1:]
xml = urllib2.urlopen(url).read()
root = ET.fromstring(xml)
places = root.findall(".//city[@alias='bath']/place")
for place in places:
if not len(stations) or place.get("number") in stations:
print "%s: %s (%s)" % (
place.get("name"), place.get("bikes"), place.get("bike_numbers")
)
date = datetime.datetime.strptime(xml[-25:], '<!-- %d.%m.%Y %H:%M -->')
print 'Updated: %s (CET)' % date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment