Skip to content

Commit

Permalink
Add weather conditions to @wx response
Browse files Browse the repository at this point in the history
  • Loading branch information
earldouglas committed Jan 21, 2024
1 parent eabff04 commit fa52921
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions modules/producers/src/main/scala/sectery/producers/Weather.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,21 @@ object OpenWeatherMap:
implicit val decoder: JsonDecoder[OneCall] =
DeriveJsonDecoder.gen[OneCall]

case class Weather(
main: String,
description: String
)

object Weather:
implicit val decoder: JsonDecoder[Weather] =
DeriveJsonDecoder.gen[Weather]

case class Current(
temp: Float,
humidity: Float,
wind_speed: Float,
uvi: Float
uvi: Float,
weather: List[Weather]
)

object Current:
Expand Down Expand Up @@ -384,12 +394,15 @@ class Weather(openWeatherMapApiKey: String, airNowApiKey: String)
(
List(
f"${p.shortName}: ${wx.current.temp}%.0f°",
f"humidity ${wx.current.humidity}%.0f%%",
f"wind ${wx.current.wind_speed}%.0f mph",
f"UV ${wx.current.uvi.toInt}"
) ++ wx.aqi.map(p =>
s"${p.name} ${p.value} (${p.category})"
)
f"hum ${wx.current.humidity}%.0f%%",
f"wnd ${wx.current.wind_speed}%.0f mph"
) ++ wx.current.weather.map { w =>
w.description
} ++ List(
f"uv ${wx.current.uvi.toInt}"
) ++ wx.aqi.map { p =>
s"${p.name.toLowerCase} ${p.value}"
}
).mkString(", ")
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object WeatherSpec extends ProducerSpec:
List(
Tx(
"#foo",
"San Francisco: 44°, humidity 65%, wind 10 mph, UV 0, O3 15 (Good), PM2.5 0 (Good)"
"San Francisco: 44°, hum 65%, wnd 10 mph, few clouds, uv 0, o3 15, pm2.5 0"
)
)
),
Expand All @@ -96,7 +96,7 @@ object WeatherSpec extends ProducerSpec:
Tx("#foo", "bar: wx set to san francisco"),
Tx(
"#foo",
"San Francisco: 44°, humidity 65%, wind 10 mph, UV 0, O3 15 (Good), PM2.5 0 (Good)"
"San Francisco: 44°, hum 65%, wnd 10 mph, few clouds, uv 0, o3 15, pm2.5 0"
)
)
)
Expand Down

0 comments on commit fa52921

Please sign in to comment.