Add usage
This commit is contained in:
parent
5b7b3f656b
commit
bc05a6f39d
@ -5,32 +5,46 @@ import sys
|
|||||||
|
|
||||||
import captaintrain as ct
|
import captaintrain as ct
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
print("""cheapest_ticket.py departure-station arrival-station departure-date
|
||||||
|
|
||||||
|
departure-date: any string parsable by date -d
|
||||||
|
""")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) > 3:
|
if len(sys.argv) <= 3:
|
||||||
departure = ct.station(sys.argv[1])
|
usage()
|
||||||
arrival = ct.station(sys.argv[2])
|
sys.exit(1)
|
||||||
departure_time = 0
|
|
||||||
|
|
||||||
with subprocess.Popen(["date", "-d", sys.argv[3], "-u", "-Iseconds"], stdout=subprocess.PIPE) as f:
|
departure = ct.station(sys.argv[1])
|
||||||
departure_time = f.stdout.read().strip().decode()
|
if departure is None:
|
||||||
|
print("Unknown station '%s'" % sys.argv[1])
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if departure_time == 0 or departure_time == "":
|
arrival = ct.station(sys.argv[2])
|
||||||
sys.exit(1)
|
if arrival is None:
|
||||||
else:
|
print("Unknown station '%s'" % sys.argv[2])
|
||||||
departure_time = ct.parse_datetime(departure_time)
|
sys.exit(1)
|
||||||
|
|
||||||
print("From:", departure.name, departure.id)
|
departure_time = 0
|
||||||
print("To:", arrival.name, arrival.id)
|
|
||||||
print("Departure:", departure_time)
|
|
||||||
|
|
||||||
#with open("res.json") as f:
|
with subprocess.Popen(["date", "-d", sys.argv[3], "-u", "-Iseconds"], stdout=subprocess.PIPE) as f:
|
||||||
# import json
|
departure_time = f.stdout.read().strip().decode()
|
||||||
# res = ct.Search(**json.load(f))
|
|
||||||
|
|
||||||
res = ct.search(departure, arrival, departure_time)
|
if departure_time == 0 or departure_time == "":
|
||||||
min_trips = ct.cheapest_trips(res.trips)
|
sys.exit(1)
|
||||||
for trip in min_trips:
|
|
||||||
print(trip)
|
|
||||||
else:
|
else:
|
||||||
print("usage")
|
departure_time = ct.parse_datetime(departure_time)
|
||||||
|
|
||||||
|
print("From:", departure.name, departure.id)
|
||||||
|
print("To:", arrival.name, arrival.id)
|
||||||
|
print("Departure:", departure_time)
|
||||||
|
|
||||||
|
#with open("res.json") as f:
|
||||||
|
# import json
|
||||||
|
# res = ct.Search(**json.load(f))
|
||||||
|
|
||||||
|
res = ct.search(departure, arrival, departure_time)
|
||||||
|
min_trips = ct.cheapest_trips(res.trips)
|
||||||
|
for trip in min_trips:
|
||||||
|
print(trip)
|
||||||
|
Loading…
Reference in New Issue
Block a user