-
Notifications
You must be signed in to change notification settings - Fork 2
/
import_trassenfinder.py
81 lines (65 loc) · 3.33 KB
/
import_trassenfinder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
from __future__ import annotations
import argparse
import logging
import os.path
import pathlib
from os import PathLike
from typing import Tuple
from cli_utils import check_files, add_default_cli_args, use_default_cli_args
from geo.location_data import add_location_data_to_list
from import_brouter import import_gpx_into_tc
from importers.db_trassenfinder import DbTrassenfinderImporter, convert_waypoints_to_route
from structures import DataSet
from structures.route import TcRoute
from tc_utils import TcFile
from tc_utils.paths import add_route_to_files
def import_trasse_into_tc(trasse: PathLike | str,
tc_directory: PathLike | str = '..',
data_directory: PathLike | str = 'data',
override_stations: bool = False,
add_annotation: bool = False,
use_google: bool = False
) -> Tuple[TcFile, TcFile]:
if pathlib.Path(trasse).suffix.lower() == 'gpx':
logging.warning("GPX-Dateiendung. Versuche als Brouter-Export zu laden.")
try:
import_gpx_into_tc(trasse, tc_directory, data_directory, override_stations, add_annotation)
except Exception as e:
logging.error("Fehlgeschlagen. Versuche als Trassenfinder-Export.", exc_info=e)
data_set = DataSet.load_data(data_directory)
waypoints = DbTrassenfinderImporter().import_data(trasse)
station_json = TcFile('Station', tc_directory)
path_json = TcFile('Path', tc_directory)
route = convert_waypoints_to_route(waypoints, data_set.station_data, data_set.path_data)
tc_route = TcRoute.from_route(route, data_set.station_data, add_annotations=add_annotation)
# Add location data from Google, if necessary
add_location_data_to_list(tc_route.stations, use_google=use_google)
add_route_to_files(tc_route, station_json, path_json,
override_stations=override_stations)
return station_json, path_json
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Importiere neue Routen vom Trassenfinder in TrainCompany')
parser.add_argument('trasse', metavar='TRASSENFINDER_DATEI', type=str,
help="Die CSV-Datei, die aus Trassenfinder exportiert wurde")
add_default_cli_args(parser)
parser.add_argument('--stations_only', action='store_true', help="Fügt nur Stationen ein")
parser.add_argument('--override_stations', action='store_true',
help="Überschreibt Haltestellen, bzw. fügt spezifischere hinzu")
parser.add_argument('--annotate', action='store_true',
help="Fügt die vollen Stationsnamen hinzu. Die müssen später wieder gelöscht werden!")
parser.add_argument("--use-google", action='store_true',
help="(VERALTET) Nutzt die Google Maps-API statt Komoot Photon für fehlende Standort-Daten (API-Key erforderlich)")
args = parser.parse_args()
use_default_cli_args(args)
check_files(args.tc_directory, args.data_directory)
path_json, station_json = import_trasse_into_tc(
args.trasse,
args.tc_directory,
args.data_directory,
args.override_stations,
add_annotation=args.annotate
)
station_json.save()
if not args.stations_only:
path_json.save()