Some checks are pending
Docker / docker (push) Waiting to run
- Include actual update time in weather report - Rename watermark worker file for clarity This commit enhances the weather data report by updating the format to include the actual update time retrieved from the weather service API. Additionally, the watermark worker file has been renamed to improve readability and consistency in the naming convention.
39 lines
1.0 KiB
Ruby
39 lines
1.0 KiB
Ruby
# app/services/weather_service.rb
|
|
class WeatherService
|
|
include HTTParty
|
|
base_uri Rails.application.credentials.dig(:qweather, :uri)
|
|
|
|
def initialize
|
|
@api_key = Rails.application.credentials.qweather.token
|
|
end
|
|
|
|
def get_weather(latitude, longitude)
|
|
Rails.logger.debug "Get Weather for #{latitude},#{longitude}"
|
|
response = self.class.get(
|
|
"/weather/now",
|
|
headers: {
|
|
"X-QW-Api-Key" => "#{@api_key}"
|
|
},
|
|
query: {
|
|
location: "#{longitude},#{latitude}"
|
|
})
|
|
|
|
return nil unless response.success?
|
|
|
|
data = response["now"]
|
|
{
|
|
temperature: data["temp"].to_f,
|
|
feeling_temp: data["feelsLike"].to_f,
|
|
humidity: data["humidity"].to_f,
|
|
wind_scale: "#{data['windScale']}级",
|
|
wind_speed: data["windSpeed"].to_f,
|
|
precipitation: data["precip"].to_f,
|
|
pressure: data["pressure"].to_f,
|
|
visibility: data["vis"].to_f,
|
|
cloud: data["cloud"].to_f,
|
|
description: data["text"],
|
|
time: response["updateTime"]
|
|
}
|
|
end
|
|
end
|