diff options
author | Markus Holtermann <info@markusholtermann.eu> | 2013-06-14 13:14:51 +0200 |
---|---|---|
committer | Markus Holtermann <info@markusholtermann.eu> | 2013-06-14 13:14:51 +0200 |
commit | a7b30e1804414f3460a1006a7b92f3d34d0f8090 (patch) | |
tree | 9d635178726328ebb2622397bce5a6ab0d7f441c | |
parent | ead3e3d984b83dca494600d9c989e6d4ed21c667 (diff) | |
download | bvg-grabber-a7b30e1804414f3460a1006a7b92f3d34d0f8090.tar.gz bvg-grabber-a7b30e1804414f3460a1006a7b92f3d34d0f8090.tar.bz2 bvg-grabber-a7b30e1804414f3460a1006a7b92f3d34d0f8090.zip |
Add a CLI script to fetch departures
-rwxr-xr-x | bvg-grabber.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/bvg-grabber.py b/bvg-grabber.py new file mode 100755 index 0000000..318aded --- /dev/null +++ b/bvg-grabber.py @@ -0,0 +1,65 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +import argparse +import sys + +from bvggrabber.api.actualdeparture import ActualDepartureQueryApi + +from bvggrabber.api.scheduleddeparture import ScheduledDepartureQueryApi, Vehicle + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser( + description='Query the BVG-website for departures') + parser.add_argument('station', type=str, help='The station to query') + parser.add_argument('file', type=str, help='Path to file') + parser.add_argument('--vehicle', type=str, nargs='*', + help='''Vehicles which shall be queried, + if non given actualdepartue (bus) + will be used''') + parser.add_argument('--limit', type=int, help='Max departures to query') + args = parser.parse_args() + + query = None + res = None + if args.vehicle: + vehicles = 0 + bus = False + for vehicle in args.vehicle: + if vehicle == 'S': + vehicles |= Vehicle.S + elif vehicle == 'U': + vehicles |= Vehicle.U + elif vehicle == 'TRAM': + vehicles |= Vehicle.TRAM + elif vehicle == 'BUS': + bus = True + elif vehicle == 'FERRY': + vehicles |= Vehicle.FERRY + elif vehicle == 'RB': + vehicles |= Vehicle.RB + elif vehicle == 'IC': + vehicles |= Vehicle.IC + limit = 9 + if args.limit: + limit = args.limit + + if bus: + aquery = ActualDepartureQueryApi(args.station) + query = ScheduledDepartureQueryApi(args.station, vehicles, limit=limit) + res = query.call() + res2 = aquery.call() + res.merge(res2) + else: + query = ActualDepartureQueryApi(args.station) + res = query.call() + + if args.file == 'stdout': + print(res.to_json, file=sys.stdout) + else: + file = open(args.file, 'w') + print(res.to_json, file=file) + file.close() + |