Skip to content

Instantly share code, notes, and snippets.

@oisin
Created October 2, 2020 21:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Get the tide times for Dun Laoghaire
#!/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