summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-09-21 19:56:55 +0200
committerTom Barrett <tom@tombarrett.xyz>2021-09-21 19:56:55 +0200
commit83f658e9f9412108a45847961b2d82b4c4f0acaa (patch)
treecbd9d0c549b96f2e0dcb05c98e0e6be3c0a5151f
parent183b9176f79bb5497595366bab342f19f144e223 (diff)
prettier list generators
-rwxr-xr-xdb26
1 files changed, 17 insertions, 9 deletions
diff --git a/db b/db
index 0a87ab2..d66401f 100755
--- a/db
+++ b/db
@@ -19,20 +19,28 @@ elif argv[-1] == "Mettingen":
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
+
+ timetablestoplists = [
+ timetablestoplist
+ for timetablestoplists in ET.fromstring(requests.get(url, headers=headers).text)
+ for timetablestoplist in timetablestoplists
+ ]
+ departures = [
+ timetablestoplist
+ for timetablestoplist in timetablestoplists
+ if timetablestoplist.tag == "dp"
+ ]
+
+ return [
+ departure.attrib
+ for departure in departures
+ if "Bad Cannstatt" in str(departure.attrib)
+ ]
potential = get(datetime.now().strftime("%-y%m%d/%-H"))