Compact print format by default, proper separation of line choices
This commit is contained in:
parent
9b0bbc66ea
commit
8e6a359396
38
monitor.py
38
monitor.py
@ -182,21 +182,41 @@ def fixup_data(d: dict) -> dict:
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def print_trip(trip: dict) -> None:
|
def print_trip(trip: dict, full_text: bool = False) -> None:
|
||||||
trip_part = "The {}:{} {} (???:{}: :{}) service to {} ".format(trip['orgHour'], trip['orgMinute'],
|
if full_text:
|
||||||
trip['lineNumber'], trip['lineCode'],
|
fmt = {
|
||||||
trip['directionCode'], trip['direction'])
|
"cancelled": "is cancelled.",
|
||||||
|
"late": "is {} min late.",
|
||||||
|
"early": "is {} min early.",
|
||||||
|
"on_time": "is on time.",
|
||||||
|
"no_rt": "has no real-time data.",
|
||||||
|
"trip": "The {}:{} {} service to {} "
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
fmt = {
|
||||||
|
"cancelled": "cancelled",
|
||||||
|
"late": "+{} min",
|
||||||
|
"early": "-{} min",
|
||||||
|
"on_time": "on time",
|
||||||
|
"no_rt": "n/a",
|
||||||
|
"trip": "{}:{} {:<6}-> {:<38}"
|
||||||
|
}
|
||||||
|
|
||||||
|
def fmt_trip(fmt_str: str, fmt_args: List[str] = []) -> str:
|
||||||
|
return (fmt['trip'] + fmt_str).format(trip['orgHour'], trip['orgMinute'], trip['lineNumber'], trip['direction'],
|
||||||
|
*fmt_args)
|
||||||
|
|
||||||
if has_realtime(trip):
|
if has_realtime(trip):
|
||||||
if is_cancelled(trip):
|
if is_cancelled(trip):
|
||||||
print(trip_part + "is cancelled.")
|
print(fmt_trip(fmt['cancelled']))
|
||||||
elif is_late(trip):
|
elif is_late(trip):
|
||||||
print(trip_part + "is {} minutes late.".format(trip['delay']))
|
print(fmt_trip(fmt['late'], fmt_args=[trip['delay']]))
|
||||||
elif is_early(trip):
|
elif is_early(trip):
|
||||||
print(trip_part + "is {} minutes early.".format(-trip['delay']))
|
print(fmt_trip(fmt['early'], fmt_args=[-trip['delay']]))
|
||||||
elif is_on_time(trip):
|
elif is_on_time(trip):
|
||||||
print(trip_part + "is on time.")
|
print(fmt_trip(fmt['on_time']))
|
||||||
else:
|
else:
|
||||||
print(trip_part + "has no real-time data.")
|
print(fmt_trip(fmt['no_rt']))
|
||||||
|
|
||||||
|
|
||||||
def get_next_refresh(data: dict):
|
def get_next_refresh(data: dict):
|
||||||
|
7
setup.py
7
setup.py
@ -64,9 +64,8 @@ def get_lines(station_id: int) -> List[str]:
|
|||||||
page = False
|
page = False
|
||||||
if page:
|
if page:
|
||||||
print("Paging in batches of 20 results.")
|
print("Paging in batches of 20 results.")
|
||||||
results_displayed = 0
|
|
||||||
for ptr in range(len(results)):
|
for ptr in range(len(results)):
|
||||||
if ptr % 20 == 0 or ptr == len(results) - 1 and ptr != 0:
|
if (ptr % 20 == 0 or ptr == len(results) - 1) and ptr != 0:
|
||||||
choices += input("Please input your choices as a space-separated list (e.g. '0 2 7 15'):\n") + ' '
|
choices += input("Please input your choices as a space-separated list (e.g. '0 2 7 15'):\n") + ' '
|
||||||
print(str(ptr) + ". " + results[ptr]['name'])
|
print(str(ptr) + ". " + results[ptr]['name'])
|
||||||
else:
|
else:
|
||||||
@ -113,3 +112,7 @@ def setup() -> None:
|
|||||||
print("Please save the following output to 'vrr.ini' and adjust any further settings:")
|
print("Please save the following output to 'vrr.ini' and adjust any further settings:")
|
||||||
print("\n" * 3)
|
print("\n" * 3)
|
||||||
cfg.write(sys.stdout)
|
cfg.write(sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
setup()
|
||||||
|
36
vrr.ini
36
vrr.ini
@ -1,26 +1,16 @@
|
|||||||
; =====================================
|
|
||||||
; VRR_ACCOUNTABILITY CONFIGURATION FILE
|
|
||||||
; =====================================
|
|
||||||
; You may generate a configuration file using ./monitor.py -s
|
|
||||||
|
|
||||||
[crawl]
|
[crawl]
|
||||||
; A valid EFA station ID. This can be obtained in the Öffi "departures" view or by inspecting
|
station_id = 20021002
|
||||||
; the regular POST requests on abfahrtsmonitor.vrr.de.
|
use_long_distance = yes
|
||||||
station_id=20021002
|
use_regional_trains = yes
|
||||||
; The server allows filtering by transport mode. Set those preferences here.
|
use_commuter_trains = yes
|
||||||
use_long_distance=yes
|
use_underground_trains = yes
|
||||||
use_regional_trains=yes
|
use_trams = yes
|
||||||
use_commuter_trains=yes
|
use_buses = yes
|
||||||
use_underground_trains=yes
|
use_elevated_trains = yes
|
||||||
use_trams=yes
|
use_lines = swk:02052: :R,swk:02052: :H,swk:02054: :H,swk:02054: :R,swk:02058: :R,swk:02058: :H,swk:02060: :R,swk:02060: :H,swk:02061: :H,swk:02061: :R,bvr:88076:W:H,swk:02152:p:H,swk:02152:p:R,swk:02158:p:R,swk:02158:p:H,rbg:70070: :H,rbg:70070: :R,rbg:70076: :H,rbg:70076: :R,ddb:90E10: :H,ddb:90E10:P:R
|
||||||
use_buses=yes
|
|
||||||
use_elevated_trains=yes
|
|
||||||
; The server allows filtering by line and direction. These line names can be
|
|
||||||
; obtained by inspecting the POST requests on abfahrtsmonitor.vrr.de.
|
|
||||||
use_lines=rbg:70070: :H,rbg:70070: :R,rbg:70076: :H,rbg:70076: :H
|
|
||||||
|
|
||||||
[db]
|
[db]
|
||||||
user=vrr
|
user = vrr
|
||||||
pass=vrr
|
pass = vrr
|
||||||
database=vrr
|
host = localhost
|
||||||
host=localhost
|
database = vrr
|
Loading…
Reference in New Issue
Block a user