test
This commit is contained in:
parent
3daf8babe5
commit
b2d741d788
|
|
@ -4,7 +4,7 @@ class RulingWeatherSetting
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
weather_api_url = "https://opendata.cwa.gov.tw".freeze
|
WEATHER_API_URL = "https://opendata.cwa.gov.tw".freeze
|
||||||
|
|
||||||
field :time_offset, type: String, default: "+8"
|
field :time_offset, type: String, default: "+8"
|
||||||
field :location, type: String, default: ""
|
field :location, type: String, default: ""
|
||||||
|
|
@ -41,7 +41,7 @@ class RulingWeatherSetting
|
||||||
time_now = DateTime.now.new_offset(self.time_offset)
|
time_now = DateTime.now.new_offset(self.time_offset)
|
||||||
today = time_now.strftime("%Y-%m-%d")
|
today = time_now.strftime("%Y-%m-%d")
|
||||||
custom_dataid = custom_dataid || self.dataid
|
custom_dataid = custom_dataid || self.dataid
|
||||||
url = "#{weather_api_url}/api/v1/rest/datastore/#{custom_dataid}.json"
|
url = "#{WEATHER_API_URL}/api/v1/rest/datastore/#{custom_dataid}.json"
|
||||||
startt = "#{today}T00:00:00"
|
startt = "#{today}T00:00:00"
|
||||||
endt = "#{today}T23:59:59"
|
endt = "#{today}T23:59:59"
|
||||||
custom_location = custom_location || self.location
|
custom_location = custom_location || self.location
|
||||||
|
|
@ -113,7 +113,7 @@ class RulingWeatherSetting
|
||||||
if timeout_flag
|
if timeout_flag
|
||||||
rain = cache["rain"].to_f rescue 0.0
|
rain = cache["rain"].to_f rescue 0.0
|
||||||
else
|
else
|
||||||
url2 = "#{weather_api_url}/api/v1/rest/datastore/O-A0002-001.json"
|
url2 = "#{WEATHER_API_URL}/api/v1/rest/datastore/O-A0002-001.json"
|
||||||
begin
|
begin
|
||||||
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)
|
||||||
|
|
@ -150,7 +150,7 @@ class RulingWeatherSetting
|
||||||
time_now = DateTime.now.utc.new_offset(self.time_offset)
|
time_now = DateTime.now.utc.new_offset(self.time_offset)
|
||||||
today = time_now.strftime("%Y-%m-%d")
|
today = time_now.strftime("%Y-%m-%d")
|
||||||
custom_dataid = custom_dataid || self.dataid
|
custom_dataid = custom_dataid || self.dataid
|
||||||
url = "#{weather_api_url}/api/v1/rest/datastore/#{custom_dataid}.json"
|
url = "#{WEATHER_API_URL}/api/v1/rest/datastore/#{custom_dataid}.json"
|
||||||
startt = "#{today}T00:00:00"
|
startt = "#{today}T00:00:00"
|
||||||
endt = "#{today}T23:59:59"
|
endt = "#{today}T23:59:59"
|
||||||
custom_location = custom_location || self.location
|
custom_location = custom_location || self.location
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue