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
|
||||
|
||||
|
||||
def print_trip(trip: dict) -> None:
|
||||
trip_part = "The {}:{} {} (???:{}: :{}) service to {} ".format(trip['orgHour'], trip['orgMinute'],
|
||||
trip['lineNumber'], trip['lineCode'],
|
||||
trip['directionCode'], trip['direction'])
|
||||
def print_trip(trip: dict, full_text: bool = False) -> None:
|
||||
if full_text:
|
||||
fmt = {
|
||||
"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 is_cancelled(trip):
|
||||
print(trip_part + "is cancelled.")
|
||||
print(fmt_trip(fmt['cancelled']))
|
||||
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):
|
||||
print(trip_part + "is {} minutes early.".format(-trip['delay']))
|
||||
print(fmt_trip(fmt['early'], fmt_args=[-trip['delay']]))
|
||||
elif is_on_time(trip):
|
||||
print(trip_part + "is on time.")
|
||||
print(fmt_trip(fmt['on_time']))
|
||||
else:
|
||||
print(trip_part + "has no real-time data.")
|
||||
print(fmt_trip(fmt['no_rt']))
|
||||
|
||||
|
||||
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
|
||||
if page:
|
||||
print("Paging in batches of 20 results.")
|
||||
results_displayed = 0
|
||||
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") + ' '
|
||||
print(str(ptr) + ". " + results[ptr]['name'])
|
||||
else:
|
||||
@ -113,3 +112,7 @@ def setup() -> None:
|
||||
print("Please save the following output to 'vrr.ini' and adjust any further settings:")
|
||||
print("\n" * 3)
|
||||
cfg.write(sys.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setup()
|
||||
|
14
vrr.ini
14
vrr.ini
@ -1,13 +1,5 @@
|
||||
; =====================================
|
||||
; VRR_ACCOUNTABILITY CONFIGURATION FILE
|
||||
; =====================================
|
||||
; You may generate a configuration file using ./monitor.py -s
|
||||
|
||||
[crawl]
|
||||
; A valid EFA station ID. This can be obtained in the Öffi "departures" view or by inspecting
|
||||
; the regular POST requests on abfahrtsmonitor.vrr.de.
|
||||
station_id = 20021002
|
||||
; The server allows filtering by transport mode. Set those preferences here.
|
||||
use_long_distance = yes
|
||||
use_regional_trains = yes
|
||||
use_commuter_trains = yes
|
||||
@ -15,12 +7,10 @@ use_underground_trains=yes
|
||||
use_trams = yes
|
||||
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
|
||||
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
|
||||
|
||||
[db]
|
||||
user = vrr
|
||||
pass = vrr
|
||||
database=vrr
|
||||
host = localhost
|
||||
database = vrr
|
Loading…
Reference in New Issue
Block a user