Apixu weather script prototype

From Chytrex, 3 Years ago, written in Ruby, viewed 90 times.
URL https://pastebin.chytrex.tk/view/12c4eb69 Shorturl http://bit.ly/2GctLsI Embed
Download Paste or View Raw
  1. #!/usr/bin/ruby
  2.  
  3. # require 'bundler/setup'
  4. # require 'iconv'
  5. # require 'apixu'
  6.  
  7. # sudo apt-get install ruby-dev
  8. # sudo gem install specific_install
  9. # sudo gem specific_install -l https://github.com/apixu/apixu-ruby.git
  10.  
  11.  
  12. # http://api.apixu.com/v1/current.json?key=92adde092a3748d8a5800249191203&q=stockholm
  13. require 'net/http'
  14. require 'json'
  15. require 'pp'
  16.  
  17.  
  18. apixukey="<APIXU-KEY-HERE>"
  19.  
  20.  
  21. apipart = "/v1/current.json?key=#{apixukey}"
  22. if ARGV[0].nil? then
  23.         input = "bohumin"
  24. else
  25.         require 'iconv'
  26.         input = Iconv.conv('ascii//translit//ignore', 'utf-8', ARGV[0])
  27. end
  28.  
  29. query = "&q=#{input}"
  30. source = Net::HTTP.get('api.apixu.com', "#{apipart}#{query}")
  31. obj = JSON.parse(source)
  32.  
  33. # pp obj
  34.  
  35. loc = "#{obj["location"]["name"]} (#{obj["location"]["region"]}, #{obj["location"]["country"]})"
  36. 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"
  37.  
  38.  
  39. puts loc
  40. puts weather
  41.  

Reply to "Apixu weather script prototype"

Here you can reply to the paste above