statusweather: Mark some things as const, increase timeout.
This commit is contained in:
parent
326d1e75b2
commit
8ef801d1df
|
@ -56,7 +56,7 @@ std::string map_icon(const std::string_view icon_id)
|
||||||
{13, "🌨"},
|
{13, "🌨"},
|
||||||
{50, "🌫"}}};
|
{50, "🌫"}}};
|
||||||
// TODO: Differenciate between day and night.
|
// TODO: Differenciate between day and night.
|
||||||
auto icon{icons.find(std::stoul(icon_id.data()))};
|
const auto icon{icons.find(std::stoul(icon_id.data()))};
|
||||||
if (icon != icons.end())
|
if (icon != icons.end())
|
||||||
{
|
{
|
||||||
return icon->second;
|
return icon->second;
|
||||||
|
@ -125,7 +125,7 @@ bool fetch_weather()
|
||||||
RestClient::Connection conn(
|
RestClient::Connection conn(
|
||||||
"http://api.openweathermap.org/data/2.5/weather");
|
"http://api.openweathermap.org/data/2.5/weather");
|
||||||
conn.FollowRedirects(true, 5);
|
conn.FollowRedirects(true, 5);
|
||||||
conn.SetTimeout(10);
|
conn.SetTimeout(120);
|
||||||
// <https://openweathermap.org/current>
|
// <https://openweathermap.org/current>
|
||||||
auto response{
|
auto response{
|
||||||
conn.get(format("?appid={0:s}&q={1:s}&units=metric", api_key, city))};
|
conn.get(format("?appid={0:s}&q={1:s}&units=metric", api_key, city))};
|
||||||
|
@ -133,7 +133,7 @@ bool fetch_weather()
|
||||||
|
|
||||||
if (response.code == 200)
|
if (response.code == 200)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(mutex_weather);
|
const std::lock_guard<std::mutex> guard(mutex_weather);
|
||||||
const auto json{nlohmann::json::parse(response.body)};
|
const auto json{nlohmann::json::parse(response.body)};
|
||||||
weather.temperature = json[0]["main"]["temp"].get<float>();
|
weather.temperature = json[0]["main"]["temp"].get<float>();
|
||||||
weather.icon = map_icon(
|
weather.icon = map_icon(
|
||||||
|
@ -152,7 +152,7 @@ void print_weather()
|
||||||
{
|
{
|
||||||
using fmt::format;
|
using fmt::format;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> guard(mutex_weather);
|
const std::lock_guard<std::mutex> guard(mutex_weather);
|
||||||
const std::string color{[]
|
const std::string color{[]
|
||||||
{
|
{
|
||||||
if (weather.temperature > 25.0)
|
if (weather.temperature > 25.0)
|
||||||
|
|
Loading…
Reference in New Issue