Get the tide times for Dun Laoghaire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# ttdl -- tide times for dun laoghaire | |
# | |
import certifi | |
import urllib3 | |
import re | |
http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) | |
r = http.request('GET', 'https://www.tidetimes.org.uk/deal-tide-times.js') | |
if r.status == 200: | |
stuff = re.findall(r'(Low|High)|(\d+:\d+)|(\d+.\d+m)', | |
r.data.decode('utf-8')) | |
# stuff is an array of tuples, convert to list and filter blanks | |
tides = list(filter(lambda i: i != '', [x for el in stuff for x in el])) | |
for i in range(0, int(len(tides) / 3)): | |
inx = i * 3 | |
(tide, time, height) = tides[inx:inx + 3] | |
print("%s tide is at %s (%s)" % (tide, time, height)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment