Created
October 15, 2015 01:09
-
-
Save DeltaWhy/66876dd00277b6075bca to your computer and use it in GitHub Desktop.
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 ruby | |
require 'open-uri' | |
class IpInfoDb | |
attr_reader :source | |
URI = "http://ipinfodb.com" | |
def initialize | |
@source = open(URI).read | |
end | |
def self.get_lat_long | |
new.get_lat_long | |
end | |
def latitude | |
@latitude ||= get("Latitude") | |
end | |
def longitude | |
@longitude ||= get("Longitude") | |
end | |
def get_lat_long | |
"#{latitude}:#{longitude}" | |
end | |
private | |
def get(which) | |
source.match(%r{<li>#{which} : (.*)</li>}) && $1 | |
end | |
end | |
puts IpInfoDb.get_lat_long |
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
#!/bin/bash | |
while ! get_lat_long >/dev/null; do | |
echo "No connection, retrying in 5 seconds" | |
sleep 5 | |
done | |
redshift-gtk -l $(get_lat_long) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment