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

45 lines
1.4 KiB
Python
Raw Normal View History

2016-05-31 14:06:15 +02:00
#!/usr/bin/python3
import itertools
import os
2016-05-31 14:50:05 +02:00
import xml.dom.minidom
2016-05-31 14:06:15 +02:00
from pprint import pprint
2016-07-18 09:37:38 +02:00
2016-05-31 14:06:15 +02:00
import MySQLdb
2016-06-02 06:56:18 +02:00
from config import database
2016-05-31 14:50:05 +02:00
from gpxlen import getTrackLength
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
2016-06-02 15:14:51 +02:00
cursor = db.cursor()
2016-05-31 14:06:15 +02:00
2016-06-02 15:14:51 +02:00
cursor.execute("SELECT lat, lon,ref FROM stationen ORDER BY ref DESC")
stations = cursor.fetchall()
id = 1
for way in itertools.combinations(stations, 2):
2016-07-18 09:37:38 +02:00
command = "routino-router --dir=/home/lukas/routino/data" \
2016-05-31 14:09:08 +02:00
" --lat1={}".format(way[0][0]) + \
" --lon1={}".format(way[0][1]) + \
" --lat2={}".format(way[1][0]) + \
" --lon2={}".format(way[1][1]) + \
2016-05-31 16:13:17 +02:00
" --quickest --transport=bicycle --output-gpx-track --quiet"
2016-05-31 14:09:08 +02:00
success = os.system(command)
if success == 0:
2016-06-02 15:14:51 +02:00
os.rename("quickest-track.gpx", "file/" + str(id) + ".gpx")
dom = xml.dom.minidom.parse("file/" + str(id) + ".gpx")
2016-05-31 14:50:05 +02:00
gpxNode = dom.firstChild
length = round(getTrackLength(gpxNode.getElementsByTagName("trk")[0]), 0)
2016-07-18 09:37:38 +02:00
# cursor.execute("REPLACE INTO connections (id, start, goal, length) VALUES (%s,%s,%s,%s)",
# (id, way[0][2], way[1][2], length))
2016-05-31 14:50:05 +02:00
else:
print(" " + str(way[0][2]) + " " + str(way[1][2]))
2016-07-18 09:37:38 +02:00
print(command)
# print(id)
2016-06-02 15:14:51 +02:00
id += 1
2016-05-31 14:06:15 +02:00
db.commit()