Last active
May 4, 2017 15:15
-
-
Save erichannell/2953a2e31fd933921b651358f57109ea to your computer and use it in GitHub Desktop.
Bikes in Barcelona
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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