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

33 lines
894 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
import MySQLdb
try:
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="Findus", # your password
db="citybike") # name of the data base
cur = db.cursor()
with open('stations.json') as data_file:
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)