From 183b9176f79bb5497595366bab342f19f144e223 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Tue, 21 Sep 2021 19:05:47 +0200 Subject: starting out --- db | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 db diff --git a/db b/db new file mode 100755 index 0000000..0a87ab2 --- /dev/null +++ b/db @@ -0,0 +1,56 @@ +#!/bin/python + +import xml.etree.ElementTree as ET +from sys import argv +from datetime import datetime, timedelta +import requests + +token = "ENTER KEY" + +# find location id with +# curl -X GET --header "Accept: application/xml" \ +# --header "Authorization: Bearer $token" \ +# "https://api.deutschebahn.com/timetables/v1/station/LOCATION" + +if argv[-1] == "Schweikheim": + location = "8005454" +elif argv[-1] == "Mettingen": + location = "8001921" + + +def get(date): + potential = [] + headers = { + "Accept": "application/xml", + "Authorization": "Bearer " + token, + } + url = "https://api.deutschebahn.com/timetables/v1/plan/" + location + "/" + date + root = ET.fromstring(requests.get(url, headers=headers).text) + for child in root: + for c in child: + if c.tag == "dp": + if "Bad Cannstatt" in str(c.attrib): + potential.append(c.attrib) + + return potential + + +potential = get(datetime.now().strftime("%-y%m%d/%-H")) +potential += get((datetime.now() + timedelta(hours=1)).strftime("%-y%m%d/%-H")) + +potential = list( + map( + lambda p: int( + (datetime.strptime(p["pt"], "%y%m%d%H%M") - datetime.now()).total_seconds() + / 60 + ), + potential, + ) +) + +potential.sort() + +potential = filter(lambda p: p > 0, potential) + +for p in potential: + print(str(p) + " minutes") -- cgit v1.2.3