Last active
September 22, 2015 17:26
-
-
Save gabtastic/380c5e3752319638ce36 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 | |
# Example output | |
# {"system_timezone":"EDT","lookup_timezone":"EDT","issue_timezone":false,"db_city":"Montreal","db_province":""} | |
require 'json' | |
# Get approximate location | |
wan = JSON.parse(`curl -s ipinfo.io`.chomp, quirks_mode: true) | |
hostname = `hostname` | |
# Lookup coordinates and determine timezone | |
tzlookup_info = JSON.parse(`curl -s http://api.teleport.org/api/locations/#{wan['loc']}/?embed=location:nearest-cities/location:nearest-city/city:timezone/tz:offsets-now`, quirks_mode:true) | |
tzlookup = tzlookup_info['_embedded']['location:nearest-cities'][0]['_embedded']['location:nearest-city']['_embedded']['city:timezone']['_embedded']['tz:offsets-now']['short_name'] | |
alfred_info = JSON.parse(`curl -s "http://api.atlas.intello.com/ihotel/devices?key=123&hostname=#{hostname}"`, quirks_mode:true) | |
city = alfred_info[0]['city'] | |
province = alfred_info[0]['province'] | |
# Find system timezone | |
system_timezone = Time.now.getlocal.zone | |
# Determine if issue is different | |
issue_timezone = false | |
unless Time.now.getlocal.zone == tzlookup | |
issue_timezone = true | |
end | |
jsonout = {"system_timezone" => system_timezone, "lookup_timezone" => tzlookup, "issue_timezone" => issue_timezone, "db_province" => province, "db_city" => city} | |
puts jsonout.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment