diff --git a/import.py b/import.py index d1c7c43..6e6c330 100755 --- a/import.py +++ b/import.py @@ -2,6 +2,9 @@ import json import sys from pprint import pprint + +import requests + from config import database import MySQLdb @@ -15,16 +18,28 @@ try: cur = db.cursor() - with open('stationLayer.json') as data_file: - data = json.load(data_file) + payload = { + "data": ( + '[out:json][timeout:25];' + 'area(3600109166)->.searchArea;' + 'node["amenity"="bicycle_rental"]["network"="Citybike Wien"](area.searchArea);' + 'out body;>;out skel qt;' + ) + + } + print("Overpass Abfrage") + r = requests.get('https://overpass-api.de/api/interpreter', params=payload) + data = r.json() + print("erfolgreich") + i = 0 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") + tags = station["tags"] + cur.execute("REPLACE INTO stationen (ref, lon, lat, name) VALUES (%s,%s,%s,%s)", + (tags["ref"], station["lon"], station["lat"], tags["name"])) + i += 1 db.commit() - + print("%s Stationen importiert" % i) db.close() except MySQLdb.Error as e: diff --git a/iterations.py b/routing.py similarity index 81% rename from iterations.py rename to routing.py index 8fd3b6e..d9463bd 100755 --- a/iterations.py +++ b/routing.py @@ -4,6 +4,7 @@ import itertools import os import xml.dom.minidom from pprint import pprint + import MySQLdb from config import database @@ -20,7 +21,7 @@ cursor.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC") stations = cursor.fetchall() id = 1 for way in itertools.combinations(stations, 2): - command = "routino-router --dir=/home/lukas/router/data" \ + command = "routino-router --dir=/home/lukas/routino/data" \ " --lat1={}".format(way[0][0]) + \ " --lon1={}".format(way[0][1]) + \ " --lat2={}".format(way[1][0]) + \ @@ -33,10 +34,11 @@ for way in itertools.combinations(stations, 2): gpxNode = dom.firstChild length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0) - cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)", - (id, way[0][2], way[1][2], length)) + # cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)", + # (id, way[0][2], way[1][2], length)) else: print(" " + str(way[0][2]) + " " + str(way[1][2])) - print(id) + print(command) + # print(id) id += 1 db.commit()