This commit is contained in:
BoHung Chiu 2021-11-19 08:20:51 +08:00
parent 01cc7848d1
commit 222477d51e
1 changed files with 3 additions and 3 deletions

View File

@ -54,8 +54,8 @@ class RulingWeatherSetting
url2 = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0002-001.json"
res2 = Net::HTTP.get_response(URI.parse("#{url2}?#{data2.to_query}"))
content2 = JSON.parse(res2.body)
weather_data2 = get_weather_data(content2)
rain = weather_data2["NOW"]["elementValue"].to_f
weather_data2 = get_weather_data(content2) rescue {}
rain = weather_data2["NOW"]["elementValue"].to_f rescue 0.0
end
result = {"mint" => mint,
"maxt" => maxt,
@ -86,7 +86,7 @@ class RulingWeatherSetting
"locationName" => custom_location}
res = Net::HTTP.get_response(URI.parse("#{url}?#{data.to_query}"))
content = JSON.parse(res.body)
weather_data = get_weather_data(content)
weather_data = get_weather_data(content) rescue {}
end
def get_weather_data(content)
if content["records"]["locations"]