Skip to content

Instantly share code, notes, and snippets.

@oisin
Last active Nov 4, 2018
Embed
What would you like to do?
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