Created
July 22, 2022 21:48
-
-
Save z3ntu/605c459f1897f0e6ce31325df7bac3d7 to your computer and use it in GitHub Desktop.
Convert BlaBlaCar Bus stops CSV into usable JS array
This file contains hidden or 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 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