import.py überarbeitet
This commit is contained in:
parent
df2199943c
commit
1741e1b454
2 changed files with 28 additions and 11 deletions
29
import.py
29
import.py
|
@ -2,6 +2,9 @@
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from config import database
|
from config import database
|
||||||
|
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
@ -15,16 +18,28 @@ try:
|
||||||
|
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
|
|
||||||
with open('stationLayer.json') as data_file:
|
payload = {
|
||||||
data = json.load(data_file)
|
"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"]:
|
for station in data["elements"]:
|
||||||
if station["type"] == "node":
|
if station["type"] == "node":
|
||||||
tags=station["tags"]
|
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"]))
|
cur.execute("REPLACE INTO stationen (ref, lon, lat, name) VALUES (%s,%s,%s,%s)",
|
||||||
print(tags["name"])
|
(tags["ref"], station["lon"], station["lat"], tags["name"]))
|
||||||
print("Commiting")
|
i += 1
|
||||||
db.commit()
|
db.commit()
|
||||||
|
print("%s Stationen importiert" % i)
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
except MySQLdb.Error as e:
|
except MySQLdb.Error as e:
|
||||||
|
|
|
@ -4,6 +4,7 @@ import itertools
|
||||||
import os
|
import os
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
|
||||||
from config import database
|
from config import database
|
||||||
|
@ -20,7 +21,7 @@ cursor.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC")
|
||||||
stations = cursor.fetchall()
|
stations = cursor.fetchall()
|
||||||
id = 1
|
id = 1
|
||||||
for way in itertools.combinations(stations, 2):
|
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]) + \
|
" --lat1={}".format(way[0][0]) + \
|
||||||
" --lon1={}".format(way[0][1]) + \
|
" --lon1={}".format(way[0][1]) + \
|
||||||
" --lat2={}".format(way[1][0]) + \
|
" --lat2={}".format(way[1][0]) + \
|
||||||
|
@ -33,10 +34,11 @@ for way in itertools.combinations(stations, 2):
|
||||||
gpxNode = dom.firstChild
|
gpxNode = dom.firstChild
|
||||||
length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0)
|
length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0)
|
||||||
|
|
||||||
cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)",
|
# cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)",
|
||||||
(id, way[0][2], way[1][2], length))
|
# (id, way[0][2], way[1][2], length))
|
||||||
else:
|
else:
|
||||||
print(" " + str(way[0][2]) + " " + str(way[1][2]))
|
print(" " + str(way[0][2]) + " " + str(way[1][2]))
|
||||||
print(id)
|
print(command)
|
||||||
|
# print(id)
|
||||||
id += 1
|
id += 1
|
||||||
db.commit()
|
db.commit()
|
Reference in a new issue