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/import.py

34 lines
844 B
Python
Raw Normal View History

2016-05-31 14:06:15 +02:00
#!/usr/bin/python3
import json
import sys
from pprint import pprint
2016-06-02 06:56:18 +02:00
from config import database
2016-05-31 14:06:15 +02:00
import MySQLdb
try:
2016-06-02 06:56:18 +02:00
db = MySQLdb.connect(database["host"],
database["user"],
database["passwd"],
database["db"])
2016-05-31 14:06:15 +02:00
cur = db.cursor()
2016-06-07 15:22:03 +02:00
with open('stationLayer.json') as data_file:
2016-05-31 14:06:15 +02:00
data = json.load(data_file)
for station in data["elements"]:
if station["type"] == "node":
tags=station["tags"]
cur.execute("INSERT INTO stationen (ref, lon, lat, name) VALUES (%s,%s,%s,%s)", (tags["ref"], station["lon"], station["lat"], tags["name"]))
print(tags["name"])
print("Commiting")
db.commit()
db.close()
except MySQLdb.Error as e:
print("Error %d: %s" % (e.args[0], e.args[1]))
sys.exit(1)