Add usage

This commit is contained in:
nemunaire 2016-07-10 18:55:53 +02:00
parent 5b7b3f656b
commit bc05a6f39d

View File

@ -5,11 +5,27 @@ 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:
usage()
sys.exit(1)
departure = ct.station(sys.argv[1]) departure = ct.station(sys.argv[1])
if departure is None:
print("Unknown station '%s'" % sys.argv[1])
sys.exit(1)
arrival = ct.station(sys.argv[2]) arrival = ct.station(sys.argv[2])
if arrival is None:
print("Unknown station '%s'" % sys.argv[2])
sys.exit(1)
departure_time = 0 departure_time = 0
with subprocess.Popen(["date", "-d", sys.argv[3], "-u", "-Iseconds"], stdout=subprocess.PIPE) as f: with subprocess.Popen(["date", "-d", sys.argv[3], "-u", "-Iseconds"], stdout=subprocess.PIPE) as f:
@ -32,5 +48,3 @@ if __name__ == "__main__":
min_trips = ct.cheapest_trips(res.trips) min_trips = ct.cheapest_trips(res.trips)
for trip in min_trips: for trip in min_trips:
print(trip) print(trip)
else:
print("usage")