Skip to content

Instantly share code, notes, and snippets.

@erichannell
Last active May 4, 2017 15:15
Show Gist options
  • Save erichannell/2953a2e31fd933921b651358f57109ea to your computer and use it in GitHub Desktop.
Save erichannell/2953a2e31fd933921b651358f57109ea to your computer and use it in GitHub Desktop.
Bikes in Barcelona
import pybikes
import csv
bike_system = "bicing"
bicing = pybikes.get(bike_system)
print bicing.meta
bicing.update()
with open (bike_system + ".csv", "wb") as inf:
writer = csv.writer(inf)
writer.writerow(["station_name", "size", "lat", "lon", "zip_code", "station_id"])
for station in xrange(len(bicing.stations)):
name = (bicing.stations[station].name).encode('utf-8')
size = int(bicing.stations[station].bikes) + int(bicing.stations[station].free)
lat = bicing.stations[station].latitude
lon = bicing.stations[station].longitude
zip = bicing.stations[station].extra['zip']
id = int(bicing.stations[station].extra['uid'])
writer.writerow([name, size, lat, lon, zip, id])
print id, name, size, lat, lon, zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment