#!/usr/bin/ruby
# require 'bundler/setup'
# require 'iconv'
# require 'apixu'
# sudo apt-get install ruby-dev
# sudo gem install specific_install
# sudo gem specific_install -l https://github.com/apixu/apixu-ruby.git
# http://api.apixu.com/v1/current.json?key=92adde092a3748d8a5800249191203&q=stockholm
require 'net/http'
require 'json'
require 'pp'
apixukey="<APIXU-KEY-HERE>"
apipart = "/v1/current.json?key=#{apixukey}"
if ARGV[0].nil? then
input = "bohumin"
else
require 'iconv'
input = Iconv.conv('ascii//translit//ignore', 'utf-8', ARGV[0])
end
query = "&q=#{input}"
source = Net::HTTP.get('api.apixu.com', "#{apipart}#{query}")
obj = JSON.parse(source)
# pp obj
loc = "#{obj["location"]["name"]} (#{obj["location"]["region"]}, #{obj["location"]["country"]})"
weather = "Temp: #{obj["current"]["temp_c"]}°C (Feels like #{obj["current"]["feelslike_c"]}°C), #{obj["current"]["condition"]["text"]}\nWind: #{obj["current"]["wind_degree"]}° #{obj["current"]["wind_dir"]} wind (#{obj["current"]["wind_kph"]}km/h - Gusting #{obj["current"]["gust_kph"]}km/h)\nPrecipitation #{obj["current"]["precip_mm"]}mm\nHumidity #{obj["current"]["humidity"]}%\nVisibility: #{obj["current"]["vis_km"]}km"
puts loc
puts weather