lib/Zeta/plugins/weather.rb in zetabot-2.0.8 vs lib/Zeta/plugins/weather.rb in zetabot-2.0.9
- old
+ new
@@ -85,25 +85,25 @@
# Open Weather map - https://openweathermap.org/api
def owm_src(location)
location = CGI.escape(location)
ac = JSON.parse(
- open(
+ RestClient.get(
"https://maps.googleapis.com/maps/api/geocode/json?address=#{location}&key=#{Config.secrets[:google]}"
- ).read, object_class: OpenStruct
+ ).body, object_class: OpenStruct
)
return nil if ac.results.nil? ## Unable to locate
ac = ac.results[0]
lat = ac.geometry.location.lat
lon = ac.geometry.location.lng
# Get Data
data = JSON.parse(
- open("https://api.openweathermap.org/data/2.5/weather?lat=#{lat}&lon=#{lon}&APPID=#{Config.secrets[:owm]}"
- ).read, object_class: OpenStruct
+ RestClient.get("https://api.openweathermap.org/data/2.5/weather?lat=#{lat}&lon=#{lon}&APPID=#{Config.secrets[:owm]}"
+ ).body, object_class: OpenStruct
)
temp = Unitwise(data.main.temp, 'K') # Data is given in kelvin
pressure = Unitwise(data.main.pressure.to_f, 'mbar')
wind = Unitwise(data.wind.speed, 'kilometer')
@@ -122,21 +122,21 @@
# DarkSky - https://darksky.net/dev
def darksky_src(location)
location = CGI.escape(location)
ac = JSON.parse(
- open("https://maps.googleapis.com/maps/api/geocode/json?address=#{location}&key=#{Config.secrets[:google]}").read,
+ RestClient.get("https://maps.googleapis.com/maps/api/geocode/json?address=#{location}&key=#{Config.secrets[:google]}").body,
object_class: OpenStruct
)
return nil if ac.results.nil? ## Unable to locate
ac = ac.results[0]
lat = ac.geometry.location.lat
lon = ac.geometry.location.lng
data = JSON.parse(
- open("https://api.darksky.net/forecast/#{Config.secrets[:darksky]}/#{lat},#{lon}").read,
+ RestClient.get("https://api.darksky.net/forecast/#{Config.secrets[:darksky]}/#{lat},#{lon}").body,
object_class: OpenStruct
)
data.ac = ac
current = data.currently
alerts = data.alerts.count rescue 0
@@ -163,26 +163,26 @@
# NOAA - https://graphical.weather.gov/xml/
def noaa_src(location)
location = CGI.escape(location)
ac = JSON.parse(
- open("https://maps.googleapis.com/maps/api/geocode/json?address=#{location}&key=#{Config.secrets[:google]}").read,
+ RestClient.get("https://maps.googleapis.com/maps/api/geocode/json?address=#{location}&key=#{Config.secrets[:google]}").body,
object_class: OpenStruct
)
return nil if ac.results.nil? ## Unable to locate
ac = ac.results[0]
lat = ac.geometry.location.lat
lon = ac.geometry.location.lng
stations = JSON.parse(
- open("https://api.weather.gov/points/#{lat},#{lon}/stations/").read
+ RestClient.get("https://api.weather.gov/points/#{lat},#{lon}/stations/").body
) rescue nil
return nil if stations.nil? ## Unable to find station. probably not in the USA
parsed = JSON.parse(
- open("#{CGI.escape(stations['observationStations'][0])}/observations/current").read,
+ RestClient.get("#{CGI.escape(stations['observationStations'][0])}/observations/current").body,
object_class: OpenStruct
)
data = parsed.properties
data.ac = ac