dsb.py 902 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python3
  2. import urllib.request
  3. import urllib.request
  4. import json
  5. # get token
  6. print("Authenticating…")
  7. urllib.request.urlretrieve("https://iphone.dsbcontrol.de/iPhoneService.svc/DSB/authid/AUTHID/AUTHPASS", "token.json")
  8. with open('token.json') as json_data:
  9. token = json.load(json_data)
  10. print("Got token: " + token + "\n")
  11. # get timetable url
  12. print("Getting url…")
  13. urllib.request.urlretrieve("https://iphone.dsbcontrol.de/iPhoneService.svc/DSB/timetables/" + token, "timetables.json")
  14. timetables = open("timetables.json", "r").read()
  15. print("Loaded JSON: " + timetables)
  16. with open('timetables.json') as json_data:
  17. data = json.load(json_data)
  18. url = data[0]["timetableurl"]
  19. print("Got url: " + url + "\n")
  20. # open url
  21. print("Opening browser…")
  22. from subprocess import call
  23. call(["lynx", url])
  24. # clean up
  25. call(["rm", "timetables.json"])
  26. call(["rm", "token.json"])