Update weather api url to https://opendata.cwa.gov.tw
This commit is contained in:
parent
cc95469a1f
commit
3e1d0253ca
|
@ -3,6 +3,9 @@ class RulingWeatherSetting
|
|||
require 'json'
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
WEATHER_API_URL = "https://opendata.cwa.gov.tw".freeze
|
||||
|
||||
field :time_offset, type: String, default: "+8"
|
||||
field :location, type: String, default: ""
|
||||
field :dataid, type: String, default: ""
|
||||
|
@ -37,9 +40,8 @@ class RulingWeatherSetting
|
|||
def get_now_info(custom_location=nil,custom_dataid=nil,custom_observatory_name=nil)
|
||||
time_now = DateTime.now.new_offset(self.time_offset)
|
||||
today = time_now.strftime("%Y-%m-%d")
|
||||
host = "https://opendata.cwb.gov.tw"
|
||||
custom_dataid = custom_dataid || self.dataid
|
||||
url = "#{host}/api/v1/rest/datastore/#{custom_dataid}.json"
|
||||
url = "#{WEATHER_API_URL}/api/v1/rest/datastore/#{custom_dataid}.json"
|
||||
startt = "#{today}T00:00:00"
|
||||
endt = "#{today}T23:59:59"
|
||||
custom_location = custom_location || self.location
|
||||
|
@ -111,7 +113,7 @@ class RulingWeatherSetting
|
|||
if timeout_flag
|
||||
rain = cache["rain"].to_f rescue 0.0
|
||||
else
|
||||
url2 = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0002-001.json"
|
||||
url2 = "#{WEATHER_API_URL}/api/v1/rest/datastore/O-A0002-001.json"
|
||||
begin
|
||||
res2 = net_http_get_response(URI.parse("#{url2}?#{data2.to_query}"))
|
||||
content2 = JSON.parse(res2.body)
|
||||
|
@ -147,9 +149,8 @@ class RulingWeatherSetting
|
|||
def test
|
||||
time_now = DateTime.now.utc.new_offset(self.time_offset)
|
||||
today = time_now.strftime("%Y-%m-%d")
|
||||
host = "https://opendata.cwb.gov.tw"
|
||||
custom_dataid = custom_dataid || self.dataid
|
||||
url = "#{host}/api/v1/rest/datastore/#{custom_dataid}.json"
|
||||
url = "#{WEATHER_API_URL}/api/v1/rest/datastore/#{custom_dataid}.json"
|
||||
startt = "#{today}T00:00:00"
|
||||
endt = "#{today}T23:59:59"
|
||||
custom_location = custom_location || self.location
|
||||
|
|
Loading…
Reference in New Issue