summaryrefslogtreecommitdiff
path: root/bvggrabber
diff options
context:
space:
mode:
authorChristian Struck <christian@struck.se>2013-01-29 17:52:09 +0100
committerChristian Struck <christian@struck.se>2013-01-29 17:52:09 +0100
commita259ff6b63839e178b7ed652a08ab1c64858120c (patch)
tree28461ccfa6811c2c15635d4b64d9e2529557a4cb /bvggrabber
parent2d00d20888b47a21848a0ce36ba8331560b60d93 (diff)
downloadbvg-grabber-a259ff6b63839e178b7ed652a08ab1c64858120c.tar.gz
bvg-grabber-a259ff6b63839e178b7ed652a08ab1c64858120c.tar.bz2
bvg-grabber-a259ff6b63839e178b7ed652a08ab1c64858120c.zip
deleted the old parsing executable from which the project started.
Diffstat (limited to 'bvggrabber')
-rwxr-xr-xbvggrabber/bvg-grabber.py57
1 files changed, 0 insertions, 57 deletions
diff --git a/bvggrabber/bvg-grabber.py b/bvggrabber/bvg-grabber.py
deleted file mode 100755
index 7ba7483..0000000
--- a/bvggrabber/bvg-grabber.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#! /usr/bin/env python3
-# -*- coding: utf-8 -*-
-import json
-import time
-
-from datetime import datetime
-from subprocess import call
-from urllib.parse import quote
-from urllib.request import urlopen
-
-
-def printOutput(stations, stationName):
- print('Station: %s' % stationName)
- if 'error' in stations:
- print(stations.get('error'))
- else:
- currentTime = int(datetime.today().hour) * 3600 + int(datetime.today().minute) * 60
- for station in stations.get('stations', []):
- for departure in station.get('departures', []):
- departureTime = int(departure['time'].replace("*", "").split(":")[0]) * 3600 + int(departure['time'].replace("*", "").split(":")[1]) * 60
- if (departureTime - currentTime) / 60 < -1:
- departureTime += 60 * 60 * 24
- if (departureTime - currentTime) / 60 < 2:
- departureText = "now"
- else:
- departureText = "in %2d min" % ((departureTime - currentTime) / 60)
- print('%-9s%-31s%12s' % (departure['line'], departure['direction'], departureText))
- print()
-
-
-def queryAPI(stationName):
- error = ''
- try:
- stations = urlopen('http://bvg-api.herokuapp.com/stations?input=' + quote(stationName))
- return json.loads(stations.read().decode('UTF-8'))
- except (IOError, UnicodeDecodeError) as e:
- error = 'Error grabbing %s!\n' % stationName
- if hasattr(e, 'reason'):
- error += 'failed to connect\n'
- error += 'Reason: ' + str(e.reason)
- elif hasattr(e, 'code'):
- error += 'serverside problem\n'
- error += 'Code: ' + str(e.code) + '\n' + str(e.headers)
- else:
- error += 'Unexpected Error'
- return {'error': error}
-
-
-if __name__ == '__main__':
- while(True):
- march = queryAPI('Marchbrücke')
- # ernst = queryAPI('U Ernst-Reuter-Platz')
- call("clear", shell=True)
- print('%-9s%-31s%12s' % ("Line", "Destination", "Departure"))
- printOutput(march, 'Marchbrücke')
- # printOutput(ernst, 'U Ernst-Reuter-Platz')
- time.sleep(20)