Skip to content

Instantly share code, notes, and snippets.

@z3ntu
Created July 22, 2022 21:48
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 z3ntu/605c459f1897f0e6ce31325df7bac3d7 to your computer and use it in GitHub Desktop.
Save z3ntu/605c459f1897f0e6ce31325df7bac3d7 to your computer and use it in GitHub Desktop.
Convert BlaBlaCar Bus stops CSV into usable JS array
import csv
def truncate(n):
# Truncate number to 5 digits
return int(float(n) * 100000) / 100000
# curl -O https://bus-api.blablacar.com/gtfs.zip && unzip gtfs.zip stops.txt
with open('stops.txt', 'r') as csvfile:
reader = csv.DictReader(csvfile)
print("var stops = {")
for row in reader:
lat = truncate(row["stop_lat"])
lon = truncate(row["stop_lon"])
print(f' "{row["stop_id"]}": {{name: "{row["stop_name"]}", coords: [{lat}, {lon}]}},')
print("};")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment