Skip to content

Commit

Permalink
Fix file format
Browse files Browse the repository at this point in the history
Refs: #52
  • Loading branch information
orontee committed Oct 5, 2023
1 parent 4c54668 commit ae2c69c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Json::Value taranis::HttpClient::get(const std::string &url) {
try {
if (not Json::parseFromStream(reader, input_stream, &root, &json_errors)) {
BOOST_LOG_TRIVIAL(error)
<< "JSON parser error " << json_errors << " " << url;
<< "JSON parser error " << json_errors << " " << url;
}
} catch (const Json::Exception& error) {
} catch (const Json::Exception &error) {
BOOST_LOG_TRIVIAL(error) << error.what();
}
return root;
Expand Down
29 changes: 18 additions & 11 deletions src/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ Condition Service::extract_condition(const Json::Value &value) {
BOOST_LOG_TRIVIAL(debug) << "Extracting weather condition from JSON value";

const auto date = static_cast<time_t>(value.get("dt", 0).asLargestInt());
const auto sunrise = static_cast<time_t>(value.get("sunrise", 0).asLargestInt());
const auto sunset = static_cast<time_t>(value.get("sunset", 0).asLargestInt());
const auto sunrise =
static_cast<time_t>(value.get("sunrise", 0).asLargestInt());
const auto sunset =
static_cast<time_t>(value.get("sunset", 0).asLargestInt());
const auto temperature = value.get("temp", NAN).asDouble();
const auto felt_temperature = value.get("feels_like", NAN).asDouble();
const auto pressure = value.get("pressure", 0).asInt();
Expand Down Expand Up @@ -204,10 +206,14 @@ DailyCondition Service::extract_daily_condition(const Json::Value &value) {
BOOST_LOG_TRIVIAL(debug) << "Extracting daily condition from JSON value";

const auto date = static_cast<time_t>(value.get("dt", 0).asLargestInt());
const auto sunrise = static_cast<time_t>(value.get("sunrise", 0).asLargestInt());
const auto sunset = static_cast<time_t>(value.get("sunset", 0).asLargestInt());
const auto moonrise = static_cast<time_t>(value.get("moonrise", 0).asLargestInt());
const auto moonset = static_cast<time_t>(value.get("moonset", 0).asLargestInt());
const auto sunrise =
static_cast<time_t>(value.get("sunrise", 0).asLargestInt());
const auto sunset =
static_cast<time_t>(value.get("sunset", 0).asLargestInt());
const auto moonrise =
static_cast<time_t>(value.get("moonrise", 0).asLargestInt());
const auto moonset =
static_cast<time_t>(value.get("moonset", 0).asLargestInt());
const auto moon_phase = value.get("moon_phase", NAN).asDouble();
const auto pressure = value.get("pressure", 0).asInt();
const auto humidity = value.get("humidity", 0).asInt();
Expand Down Expand Up @@ -269,11 +275,12 @@ std::vector<Alert> Service::extract_alerts(const Json::Value &value) {
std::vector<Alert> alerts;

for (auto &alert_value : value) {
const Alert alert{alert_value.get("sender_name", "").asString(),
alert_value.get("event", "").asString(),
static_cast<time_t>(alert_value.get("start", 0).asLargestInt()),
static_cast<time_t>(alert_value.get("end", 0).asLargestInt()),
alert_value.get("description", "").asString()};
const Alert alert{
alert_value.get("sender_name", "").asString(),
alert_value.get("event", "").asString(),
static_cast<time_t>(alert_value.get("start", 0).asLargestInt()),
static_cast<time_t>(alert_value.get("end", 0).asLargestInt()),
alert_value.get("description", "").asString()};
alerts.push_back(alert);
}
return alerts;
Expand Down

0 comments on commit ae2c69c

Please sign in to comment.