lib/Zeta/plugins/weather.rb in zetabot-0.0.18 vs lib/Zeta/plugins/weather.rb in zetabot-0.0.19
- old
+ new
@@ -93,11 +93,12 @@
msg.reply(reply_msg)
end
# ?almanac <location>
def almanac(msg,locale)
- url = URI.encode "http://api.wunderground.com/api/#{Config.secrets[:wunderground]}/almanac/q/#{locale}.json"
+ autocomplete = JSON.parse( open(URI.encode("http://autocomplete.wunderground.com/aq?query=#{locale}")).read )
+ url = URI.encode("http://api.wunderground.com/api/#{Config.secrets[:wunderground]}/almanac/#{autocomplete['RESULTS'][0]['l']}.json")
location = JSON.parse(
# RestClient.get(url)
open(url).read
)
return msg.reply "No results found for #{query}." if location.nil?
@@ -128,10 +129,11 @@
end
# -private
def geolookup(locale)
- url = URI.encode "http://api.wunderground.com/api/#{Config.secrets[:wunderground]}/geolookup/q/#{locale}.json"
+ autocomplete = JSON.parse( open(URI.encode("http://autocomplete.wunderground.com/aq?query=#{locale}")).read )
+ url = URI.encode("http://api.wunderground.com/api/#{Config.secrets[:wunderground]}/geolookup/#{autocomplete['RESULTS'][0]['l']}.json")
location = JSON.parse(
open(url).read
)
location['location']['l']
rescue