summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-09-21 19:05:47 +0200
committerTom Barrett <tom@tombarrett.xyz>2021-09-21 19:05:47 +0200
commit183b9176f79bb5497595366bab342f19f144e223 (patch)
treed48c97d1ba9661638754206dc201fb79d1488b39
starting out
-rwxr-xr-xdb56
1 files changed, 56 insertions, 0 deletions
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")