Closed farbro closed 1 year ago
I would suggest you only add --train-canceled
with true
as default and thereby you already have the option to set false to skip cancelled trains.
Should not be mixed with deleted
which is something else
I would suggest you only add
--train-canceled
withtrue
as default and thereby you already have the option to set false to skip cancelled trains.
But wouldn't that break backwards compatibility? How would you then request both canceled and non-canceled, as it is originally?
I would see it like this with --train-canceled
Probably we should reverse this and call it --exclude-canceled
or something
Ah I get it, see my new commit. We do lose the ability to filter by canceled trains, but that is a feature that will probably never be used anyway.
Thanks for your review. I applied your suggested changes and also bumped up the version.
Did you test it?
I thought so. Now I tested it again, by finding a canceled departure, querying it with -date-time
and toggling it with -exclude-canceled-trains
.
$ python3 pytrafikverket.py -key <my-key> -method get-next-train-stop -from-station "Stockholm C" -to-station "Norrköping C" -date-time "2022-11-27T21:38:00"
from_station_signature: Cst
to_station_signature: Nr
advertised_time_at_location = 2022-11-27 21:38:00+01:00
canceled = True
deviations = ['Inställt']
estimated_time_at_location = None
id = 1500adde-115d-43e5-08da-c443c281f393
modified_time = 2022-11-27 15:32:03.108000
other_information = ['Movingo gäller.']
product_description = ['Mälartåg']
time_at_location = None
$ python3 pytrafikverket.py -key <my-key> -method get-next-train-stop -from-station "Stockholm C" -to-station "Norrköping C" -date-time "2022-11-27T21:38:00" -exclude-canceled-trains
from_station_signature: Cst
to_station_signature: Nr
advertised_time_at_location = 2022-11-27 21:54:00+01:00
canceled = False
deviations = []
estimated_time_at_location = None
id = 1500adde-115d-43e5-08da-c443d1e13afd
modified_time = 2022-11-13 06:24:58.810000
other_information = ['Movingo gäller ej.']
product_description = ['SJ InterCity']
time_at_location = None
-get-train-stop` behaves similarly but throws an exception for the canceled departure.
I guess it would make sense to get an exception when filtering out canceled but you hit a canceled on the result. What is the exception you get?
What is the exception you get?
ValueError: No TrainAnnouncement found
thrown by
get_train_stop(...)
itself: https://github.com/farbro/pytrafikverket/blob/master/pytrafikverket/trafikverket_train.py#L259
--train-canceled
and--train-not-canceled
to CLI app.canceled
argument for filtering inasync_get_train_stop(...)
andasync_get_next_train_stop(...)
This could possible be implemented for ferries as well, but they do not have a "Canceled" property. Instead they have something called "Deleted", but it is unclear what it does.