initial commit...
This commit is contained in:
parent
c184752399
commit
5284f9a781
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from subprocess import check_output
|
||||
from requests import get
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
|
||||
timezone = pytz.timezone('Europe/Berlin')
|
||||
|
||||
def check_ssid():
|
||||
|
||||
scanoutput = check_output(["/usr/sbin/iwlist", "wlp2s0", "scan"])
|
||||
|
||||
for line in scanoutput.split():
|
||||
line = line.decode("utf-8")
|
||||
if line[:5] == "ESSID":
|
||||
ssid = line.split('"')[1]
|
||||
return ssid
|
||||
|
||||
# Get Speed from ICE-Portal
|
||||
def get_speed_db():
|
||||
rs = "https://iceportal.de/api1/rs/status"
|
||||
response = get(rs)
|
||||
data = response.json()
|
||||
speed= data["speed"] + " km/h"
|
||||
return speed
|
||||
|
||||
def get_trip_db():
|
||||
rs = "https://iceportal.de/api1/rs/tripInfo/trip/"
|
||||
database = "trip.json"
|
||||
data = json.loads(open(database).read())
|
||||
next_stop=data["trip"]["stopInfo"]["actualNext"]
|
||||
|
||||
for i in data['trip']['stops']:
|
||||
if i['station']['evaNr'] == next_stop:
|
||||
nextStationName = i['station']['name']
|
||||
arrivalDelay = i['timetable']['arrivalDelay']
|
||||
utime=i['timetable']['actualArrivalTime']/1000
|
||||
arrivalTime = datetime.fromtimestamp(utime, tz=timezonedt).strftime('%H:%M')
|
||||
break
|
||||
tripinfo = nextStationName + arrivalTime + arrivalDelay
|
||||
return tripinfo
|
||||
|
||||
def main():
|
||||
if check_ssid() == "WIFIonICE":
|
||||
print("SPEED: "+get_speed_db()+"NEXT: "+get_trip_db())
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main()) # next section explains the use of sys.exit
|
||||
|
||||
Loading…
Reference in New Issue