Skip to content

Instantly share code, notes, and snippets.

@oisin
Last active November 4, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisin/57bc72c4ea5a3e6c52f331be902f0e30 to your computer and use it in GitHub Desktop.
Save oisin/57bc72c4ea5a3e6c52f331be902f0e30 to your computer and use it in GitHub Desktop.
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))
#!/usr/bin/env ruby
#
# ttdl -- tide times for dun laoghaire
#
require 'open-uri'
script = open('https://www.tidetimes.org.uk/deal-tide-times.js').read
regex = /(Low|High)|(\d+:\d+)|(\d+.\d+m)/
tides = script.scan(regex).flatten.reject(&:nil?)
0...(tides.count / 3).times do |i|
inx = i * 3
tide, time, height = tides[inx..inx + 2]
puts "#{tide} tide is at #{time} (#{height})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment