return None
+def template_to_json(value: Template) -> dict:
+ parameter = []
+ for p in value.params:
+ parameter.append({'value': str(p)})
+ return {
+ 'name': str(value.name),
+ 'parameter': parameter
+ }
+
class SledrunWikiTextToJsonBot(
SingleSiteBot,
x = str(Wikicode(v.nodes[:v.nodes.index(w)])).strip()
if x:
sledrun_json["public_transport_description"] = str(x)
- x = []
- y = None
+
+ public_transport_stops = []
+ public_transport_lines = []
+ ya = None
for w in v.nodes:
if isinstance(w, Template):
if w.name == 'Haltestelle':
- if y is not None:
- x.append(y)
- y = {}
+ if ya is not None:
+ public_transport_stops.append(ya)
+ ya = {}
z = w.get(1, None)
if z is not None:
- y['municipality'] = str(z)
+ ya['municipality'] = str(z)
z = w.get(2, None)
if z is not None:
- y['name_local'] = str(z)
+ ya['name_local'] = str(z)
za = str_or_none(w.get(3, None))
zb = str_or_none(w.get(4, None))
z = lonlat_ele_to_json(opt_lonlat_from_str(za), opt_uint_from_str(zb))
if len(z) > 0:
- y['position'] = z
- if y is not None:
- x.append(y)
- if len(x) > 0:
- sledrun_json['public_transport_stops'] = x
+ ya['position'] = z
+ elif w.name in ["Fahrplan Abfahrtsmonitor VVT"]:
+ ya['monitor_template'] = template_to_json(w)
+ elif w.name in ["Fahrplan Hinfahrt VVT"]:
+ ya['route_arrival_template'] = template_to_json(w)
+ elif w.name in ["Fahrplan Rückfahrt VVT"]:
+ ya['route_departure_template'] = template_to_json(w)
+ elif w.name in ["Fahrplan Linie VVT"]:
+ if ya is not None:
+ public_transport_stops.append(ya)
+ ya = None
+ y = {
+ 'timetable_template': template_to_json(w),
+ }
+ public_transport_lines.append(y)
+ if ya is not None:
+ public_transport_stops.append(ya)
+ if len(public_transport_stops) > 0:
+ sledrun_json['public_transport_stops'] = public_transport_stops
+ if len(public_transport_lines) > 0:
+ sledrun_json['public_transport_lines'] = public_transport_lines
break
for v in wikicode.get_sections(levels=[2], matches='Anreise mit dem Auto'):