diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-09-21 19:56:55 +0200 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-09-21 19:56:55 +0200 |
commit | 83f658e9f9412108a45847961b2d82b4c4f0acaa (patch) | |
tree | cbd9d0c549b96f2e0dcb05c98e0e6be3c0a5151f | |
parent | 183b9176f79bb5497595366bab342f19f144e223 (diff) |
prettier list generators
-rwxr-xr-x | db | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -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")) |