Created
December 1, 2012 02:45
-
-
Save jc00ke/4180325 to your computer and use it in GitHub Desktop.
Get Lat:Long from IP Info Database
This file contains hidden or 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 hidden or 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
gtk-redshift -l $(get_lat_long) & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment