Archived
1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
citybike/stationExport.py

46 lines
1.1 KiB
Python
Raw Normal View History

2016-06-02 15:14:51 +02:00
#!/usr/bin/python3
import json
from pprint import pprint
import MySQLdb
from config import database
db = MySQLdb.connect(database["host"],
database["user"],
database["passwd"],
database["db"])
cursor = db.cursor()
cursor.execute("SELECT lon, lat,ref,name FROM stationen ORDER BY ref DESC")
stations = cursor.fetchall()
features = []
for station in stations:
feature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
station[0],
station[1]
]
},
"properties": {
"name": station[3],
"ref": station[2]
}
}
features.append(feature)
geojsonComplete = {
"type": "FeatureCollection",
"features": features
}
# print(json.dumps(geojsonComplete, indent=4))
2016-10-01 20:41:29 +02:00
with open('www/stationLayer.json', 'w') as outfile:
2016-06-02 15:14:51 +02:00
json.dump(geojsonComplete, outfile, indent=4)
2016-10-01 20:41:29 +02:00
# with open('www/station.json', 'w') as outfile:
# json.dump(stations, outfile, indent=4)