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" 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}")) res2 = Net::HTTP.get_response(URI.parse("#{url2}?#{data2.to_query}"))
content2 = JSON.parse(res2.body) content2 = JSON.parse(res2.body)
weather_data2 = get_weather_data(content2) weather_data2 = get_weather_data(content2) rescue {}
rain = weather_data2["NOW"]["elementValue"].to_f rain = weather_data2["NOW"]["elementValue"].to_f rescue 0.0
end end
result = {"mint" => mint, result = {"mint" => mint,
"maxt" => maxt, "maxt" => maxt,
@ -86,7 +86,7 @@ class RulingWeatherSetting
"locationName" => custom_location} "locationName" => custom_location}
res = Net::HTTP.get_response(URI.parse("#{url}?#{data.to_query}")) res = Net::HTTP.get_response(URI.parse("#{url}?#{data.to_query}"))
content = JSON.parse(res.body) content = JSON.parse(res.body)
weather_data = get_weather_data(content) weather_data = get_weather_data(content) rescue {}
end end
def get_weather_data(content) def get_weather_data(content)
if content["records"]["locations"] if content["records"]["locations"]