diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4774b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/build +/cmake-build-debug +/.idea diff --git a/CMakeLists.txt b/CMakeLists.txt index 475c2db..e0d329a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,14 @@ add_executable(tzeva_adom main.cpp utils/audio_play.cpp locale/localization_get.cpp utils/localization_manager.h - utils/localization_manager.h + models/OrefAlertResponse.cpp + CONFIG.cpp + models/Interfaces/IAlertResponse.cpp + models/Interfaces/IAlert.cpp + locale/OREF_localization.cpp + models/AlertMessage_OREF.cpp + utils/OREFToTzevaAdom.cpp + models/OrefAlertResponse.cpp ) find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB REQUIRED glib-2.0) diff --git a/CONFIG.cpp b/CONFIG.cpp new file mode 100644 index 0000000..5e9d035 --- /dev/null +++ b/CONFIG.cpp @@ -0,0 +1,16 @@ +// +// Created by yawaflua on 30/10/2024. +// + +#define OREF_URL "https://www.oref.org.il/warningMessages/alert/History/AlertsHistory.json" +#define TZEVA_ADOM_URL "https://api.tzevaadom.co.il/alerts-history" +#define THREAT_IMAGES_URL "https://www.tzevaadom.co.il/static/images/threat{}.{}" +#define BELL_SOUND_URL "https://www.tzevaadom.co.il/static/sounds/bell.mp3" +#define CITIES_OREF_URL_RU "https://www.oref.org.il/districts/cities_rus.json" +#define CITIES_OREF_URL_EN "https://www.oref.org.il/districts/cities_eng.json" +#define CITIES_OREF_URL_HE "https://www.oref.org.il/districts/cities_heb.json" +#define CITIES_TZEVA_ADOM "https://www.tzevaadom.co.il/static/cities.json" +#define ALERTS_OREF "https://www.oref.org.il/alerts/alertCategories.json" +#define ALERT_TRANSLATIONS_OREF "https://www.oref.org.il/alerts/alertsTranslation.json" + + diff --git a/lang/ru.json b/lang/ru.json index 56b5b58..fa0ab99 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -9,6 +9,17 @@ "threat_7": "Неконвенциональная ракета", "threat_8": "предупреждение", "threat_9": "Учения Службы Тыла", + "missilealert": "Атака ракетами", + "uav": "Проникновение беспилотного самолета", + "nonconventional": "Неконвенциональная ракета", + "warning": "Предупреждение", + "earthquakealert1": "Землетрясение", + "earthquakealert2": "Землетрясение", + "terrorattack": "Подозрение на проникновение террористов", + "tsunami": "Цунами", + "hazmat": "Утечка опасных веществ", + "missilealertdrill": "Учения атаки ракетами", + "uavdrill": "Учения атаки беспилотников", "default": "Неназвано", "drill": "упражнения: ", "true": "да", diff --git a/locale/OREF_localization.cpp b/locale/OREF_localization.cpp new file mode 100644 index 0000000..a1840fe --- /dev/null +++ b/locale/OREF_localization.cpp @@ -0,0 +1,89 @@ +// +// Created by yawaflua on 01/11/2024. +// +#include +#include +#ifndef OREF_LOCALIZATION_CPP +#define OREF_LOCALIZATION_CPP + +#include "models/AlertMessage_OREF.cpp" +#include +#include +#include +#include +#include // Подключение библиотеки JSON +#include +#include "./CONFIG.cpp" + +namespace tzeva_adom { + //class AlertMessage; + + class LocalizationManager { + private: + std::vector jsonAlertsTranslate; + size_t static WriteCallbackAlerts(void* contents, size_t size, size_t nmemb, std::string* output) { + output->append(static_cast(contents), size * nmemb); + return size * nmemb; + } + + std::string loadLocalizations(std::string lang) { + CURL* curl = curl_easy_init(); + std::string readBuffer; + curl_easy_setopt(curl, CURLOPT_URL, ALERT_TRANSLATIONS_OREF); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallbackAlerts); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); + CURLcode res = curl_easy_perform(curl); + auto jsonResponseFromLocalization = nlohmann::json::parse(readBuffer); + jsonAlertsTranslate = jsonResponseFromLocalization.get>(); + + curl_easy_cleanup(curl); + } + + public: + LocalizationManager() = default; + virtual ~LocalizationManager() = default; + + // Загрузить языковой файл + bool loadLanguage(std::string lang) { + std::string path = std::filesystem::current_path().c_str() + fmt::format("/lang/{}.json", lang); + std::ifstream file(path); + if (!file.is_open()) { + std::cerr << "Failed to open localization file: " << lang << std::endl; + std::cerr << "Failed to open localization file: " << path << std::endl; + return false; + } + + nlohmann::json json; + file >> json; + translations[lang] = json; + return true; + } + + // Установить текущий язык + void setCurrentLanguage(const std::string& langCode) { + loadLanguage(langCode); + if (translations.find(langCode) != translations.end()) { + currentLanguage = langCode; + + } else { + std::cerr << "Language code not loaded: " << langCode << std::endl; + } + } + + // Получить переведенную строку по ключу + std::string getString(const std::string& key) const { + if (!translations.find(currentLanguage)->second.empty()) { + auto& langData = translations.at(currentLanguage); + if (langData.contains(key)) { + return langData[key]; + } + } + return "Translation not found"; + } + + private: + std::unordered_map translations; + std::string currentLanguage; + }; +} +#endif // LOCALIZATION_MANAGER_H diff --git a/main.cpp b/main.cpp index 2f293cb..c0ea72b 100644 --- a/main.cpp +++ b/main.cpp @@ -10,9 +10,12 @@ #include #include #include +#include +#include "CONFIG.cpp" #include "utils/audio_play.cpp" #include "models/AlertResponse.cpp" +#include "models/OrefAlertResponse.cpp" #include "utils/image_downloader.cpp" #include "utils/localization_manager.h" @@ -20,13 +23,14 @@ class AlertResponse; tzeva_adom::LocalizationManager localization_manager; using json = nlohmann::json; -int16_t lastId = 0; +int64_t lastId = 0; json cities_n_areas_list; bool is_cities_loaded = false; bool is_test = false; std::string this_path = boost::filesystem::current_path().c_str(); std::string lang = "en"; std::vector test_alert_variable; +bool is_oref = false; // Функция для записи данных от curl size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* output) { @@ -52,56 +56,55 @@ void process_alert(const std::string& data) { } spdlog::debug("Get first object from answer"); - auto* first_alert = new tzeva_adom::AlertResponseElement(response.at(0)); - spdlog::debug("Answer: {}", first_alert->get_id()); - - auto id = first_alert->get_id(); - - if (lastId == 0 || id == lastId) { - lastId = id; - } else { - is_alert = !is_alert; - lastId = id; - spdlog::debug("This is alert!"); + std::unique_ptr first_alert; + if (is_oref) { + spdlog::debug("OREF_alertDate: {}", response[0]["alertDate"]); + spdlog::debug("OREF_title: {}", response[0]["title"]); + spdlog::debug("OREF_data: {}", response[0]["data"]); + spdlog::debug("OREF_category: {}",std::to_string(response[0]["category"].get())); + spdlog::debug("OREF selected, create oref object"); + auto response_oref = response.at(0); + first_alert = std::make_unique(response_oref["alertDate"], response_oref["title"], response_oref["data"], response_oref["category"]); + } + else { + spdlog::debug("TzevaAdom selected, create object"); + auto response_tzeva = response.at(0); + first_alert = std::make_unique( + response_tzeva["id"].get(), + response_tzeva["description"].get(), + response_tzeva["alerts"].get()); } + auto id = first_alert->get_id(); + spdlog::debug("Answer: {}", id); + + if (!(lastId == 0 || id == lastId)) { + is_alert = true; + spdlog::debug("This is alert!"); + } + lastId = id; + if (is_alert || is_test) { - is_test = !is_test; - // auto description = first_alert["description"].is_string() ?"": first_alert["description"].get() ; - std::string description = ""; - const std::vector alerts_array = is_test ? test_alert_variable : first_alert->get_alerts(); - std::vector cities; - std::vector threats; + is_test = false; + is_alert = false; - for (auto alerts: alerts_array) { - auto time = alerts.get_time(); - for (auto city: alerts.get_cities()) { - cities.insert(cities.begin(), city); - } + std::string cities = first_alert->get_cities(); + int threat = first_alert->get_threat(); - threats.insert(threats.begin(), alerts.get_threat()); - auto isDrill = alerts.get_is_drill(); + // spdlog::debug("Time: {}", time); + spdlog::debug("Cities: {}", cities); - - spdlog::debug("Time: {}", time); - spdlog::debug("Cities: {}", fmt::join(cities, ", ")); - - spdlog::debug("Threat Level: {}", alerts.get_threat()); - spdlog::debug("Is Drill: {}", isDrill); - } - - int threat = *std::max_element( threats.begin(), threats.end() ); std::string icon_url = boost::filesystem::current_path().c_str()+fmt::format("/threat{}.{}", std::to_string(threat), threat == 0 ? "png" : "svg"); - spdlog::debug("Threat: {}", threat); + spdlog::debug("Threat: {}", first_alert->get_threat()); spdlog::debug("Threat name: {}", localization_manager.getString(fmt::format("threat_{}", threat))); spdlog::debug("Language: {}", lang); spdlog::debug("Icon path: {}", icon_url); std::string localised_cities_names = ""; - for (auto city: cities) { + for (auto city: first_alert->get_cities_arr()) { localised_cities_names += fmt::format("{} ", cities_n_areas_list["cities"][city][lang]); } @@ -133,8 +136,9 @@ void process_alert(const std::string& data) { } - } catch (const std::exception& e) { - spdlog::error("Alert error: {}", e.what()); + } catch (...) { + std::exception_ptr e = std::current_exception(); + spdlog::error("Alert error: {}", e ? (e.__cxa_exception_type()->name()) : "null"); } @@ -150,9 +154,14 @@ void fetch_alerts_history(std::atomic& running) { curl = curl_easy_init(); // Parse cities and areas names on he, ru and en + if (is_oref && lang == "he") { + spdlog::error("Lang is not supported. Use TZEVA_ADOM"); + return; + } if (!is_cities_loaded) { std::string readBuffer; - curl_easy_setopt(curl, CURLOPT_URL, "https://www.tzevaadom.co.il/static/cities.json"); + //Only tzeva_adom variable of cities list, because thats easier to work, than oref variable(without linq) + curl_easy_setopt(curl, CURLOPT_URL, CITIES_TZEVA_ADOM); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); @@ -169,7 +178,7 @@ void fetch_alerts_history(std::atomic& running) { if (curl) { std::string readBuffer; curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0"); - curl_easy_setopt(curl, CURLOPT_URL, "https://api.tzevaadom.co.il/alerts-history"); + curl_easy_setopt(curl, CURLOPT_URL, !is_oref ? TZEVA_ADOM_URL : OREF_URL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); @@ -213,15 +222,6 @@ int main(int argc, char** argv) { spdlog::set_level(spdlog::level::debug); // Set global log level to debug if provided --debug else if (argv[i] == "-t"sv || argv[i] == "--test") { is_test = true; // Set tested variable is true - std::vector alert_to_array {tzeva_adom::Alert()}; - const auto p1 = std::chrono::system_clock::now(); - ulong t = std::chrono::duration_cast( - p1.time_since_epoch()).count(); - std::vector city_vectors{"אשדוד -יא,יב,טו,יז,מרינה,סיט", "אשדוד - ח,ט,י,יג,יד,טז"}; - alert_to_array[0].set_cities(city_vectors); - alert_to_array[0].set_time(t); - alert_to_array[0].set_threat(0); - test_alert_variable.push_back(alert_to_array[0]); } else if (argv[i] == "-l"sv || argv[i] == "--lang"sv) { is_accept_values = true; @@ -231,7 +231,6 @@ int main(int argc, char** argv) { is_accept_values = false; lang = argv[i]; spdlog::debug("Language setted to {}", lang); - } else if (argv[i] == "-h"sv || argv[i] == "--help"sv) { spdlog::info( @@ -240,10 +239,15 @@ int main(int argc, char** argv) { " -h --help: Show this message\n"\ " -d --debug: Show debug messages\n"\ " -t --test: Create test alert end exit\n"\ - " -l --lang: Choose language: ru, en, he," + " -l --lang: Choose language: ru, en, he\n"\ + " -o --oref: Use OREF uri`s for alerts"\ ""); return 0; } + else if (argv[i] == "-o"sv || argv[i] == "--oref"sv) { + is_oref = true; + spdlog::debug("Selected provider: OREF"); + } last_flag = argv[i]; } @@ -253,7 +257,7 @@ int main(int argc, char** argv) { if (!boost::filesystem::exists(this_path+fmt::format("/threat{}.{}", std::to_string(i), i == 0 ? "png" : "svg"))) { tzeva_adom::download_file( fmt::format( - "https://www.tzevaadom.co.il/static/images/threat{}.{}", + THREAT_IMAGES_URL, std::to_string(i), i == 0 ? "png" : "svg"), fmt::format("threat{}.{}", std::to_string(i), i == 0 ? "png" : "svg") ); @@ -265,7 +269,7 @@ int main(int argc, char** argv) { //Download tzeva-adom bell sound if (!boost::filesystem::exists(this_path+fmt::format("/bell.mp3"))) { tzeva_adom::download_file( - "https://www.tzevaadom.co.il/static/sounds/bell.mp3", + BELL_SOUND_URL, fmt::format("bell.mp3") ); } diff --git a/models/AlertMessage_OREF.cpp b/models/AlertMessage_OREF.cpp new file mode 100644 index 0000000..ebda0d2 --- /dev/null +++ b/models/AlertMessage_OREF.cpp @@ -0,0 +1,69 @@ +// +// Created by yawaflua on 01/11/2024. +// +#include +#include + +namespace tzeva_adom { + class AlertMessage { + public: + std::string heb; + std::string eng; + std::string rus; + std::string arb; + int catId; + int matrixCatId; + std::string hebTitle; + std::string engTitle; + std::string rusTitle; + std::string arbTitle; + + // AlertMessage( + // const std::string& heb, const std::string& eng, const std::string& rus, const std::string& arb, + // int catId, int matrixCatId, + // const std::string& hebTitle, const std::string& engTitle, + // const std::string& rusTitle, const std::string& arbTitle + // ) + // : heb(heb), eng(eng), rus(rus), arb(arb), + // catId(catId), matrixCatId(matrixCatId), + // hebTitle(hebTitle), engTitle(engTitle), + // rusTitle(rusTitle), arbTitle(arbTitle) {} + + AlertMessage() = default; + virtual ~AlertMessage() = default; + + + + // JSON сериализация + friend void to_json(nlohmann::json& j, const AlertMessage& message) { + j = nlohmann::json{ + {"heb", message.heb}, + {"eng", message.eng}, + {"rus", message.rus}, + {"arb", message.arb}, + {"catId", message.catId}, + {"matrixCatId", message.matrixCatId}, + {"hebTitle", message.hebTitle}, + {"engTitle", message.engTitle}, + {"rusTitle", message.rusTitle}, + {"arbTitle", message.arbTitle} + }; + } + + // JSON десериализация + friend void from_json(const nlohmann::json& j, AlertMessage& message) { + j.at("heb").get_to(message.heb); + j.at("eng").get_to(message.eng); + j.at("rus").get_to(message.rus); + j.at("arb").get_to(message.arb); + j.at("catId").get_to(message.catId); + j.at("matrixCatId").get_to(message.matrixCatId); + j.at("hebTitle").get_to(message.hebTitle); + j.at("engTitle").get_to(message.engTitle); + j.at("rusTitle").get_to(message.rusTitle); + j.at("arbTitle").get_to(message.arbTitle); + } + + using AlertingMessages = std::vector; + }; +} \ No newline at end of file diff --git a/models/AlertResponse.cpp b/models/AlertResponse.cpp index b1e877b..74c5e90 100644 --- a/models/AlertResponse.cpp +++ b/models/AlertResponse.cpp @@ -11,8 +11,11 @@ #include #include +#include #include #include +#include "models/Interfaces/IAlertResponse.cpp" +#include "models/Interfaces/IAlert.cpp" namespace tzeva_adom { using nlohmann::json; @@ -31,9 +34,16 @@ namespace tzeva_adom { } #endif - class Alert { + class Alert : public IAlert{ public: Alert() = default; + Alert( + const int64_t time, + const std::vector& cities, + int64_t threat, + bool is_drill + ) : + time(time), cities(cities), threat(threat), is_drill(is_drill) {}; virtual ~Alert() = default; private: @@ -48,10 +58,12 @@ namespace tzeva_adom { void set_time(const int64_t & value) { this->time = value; } const std::vector & get_cities() const { return cities; } + std::vector get_cities() override { return cities; } std::vector & get_mutable_cities() { return cities; } void set_cities(const std::vector & value) { this->cities = value; } const int64_t & get_threat() const { return threat; } + int get_threat() override { return threat; } int64_t & get_mutable_threat() { return threat; } void set_threat(const int64_t & value) { this->threat = value; } @@ -60,9 +72,25 @@ namespace tzeva_adom { void set_is_drill(const bool & value) { this->is_drill = value; } }; - class AlertResponseElement { + class AlertResponseElement : public IAlertResponse { public: AlertResponseElement() = default; + AlertResponseElement( + const int id, + const nlohmann::json description, + const nlohmann::json alerts) + : id(id), description(description) { + for (const auto& alertJson : alerts) { + + int64_t time = alertJson["time"]; + std::vector cities = alertJson["cities"].get>(); + int64_t threat = alertJson["threat"]; + bool is_drill = alertJson["isDrill"]; + + Alert _alert = *std::make_unique(time, cities, threat, is_drill).get(); + this->alerts.push_back(_alert); + } + } virtual ~AlertResponseElement() = default; private: @@ -71,10 +99,19 @@ namespace tzeva_adom { std::vector alerts; public: - const int64_t & get_id() const { return id; } + int get_id() override { return id; } + const int64_t &get_id() const { return id; } int64_t & get_mutable_id() { return id; } void set_id(const int64_t & value) { this->id = value; } + int get_threat() override { + int i = 0; + for (auto alert: alerts) { + i += alert.get_threat(); + } + return i / alerts.size(); + } + const nlohmann::json & get_description() const { return description; } nlohmann::json & get_mutable_description() { return description; } void set_description(const nlohmann::json & value) { this->description = value; } @@ -82,6 +119,26 @@ namespace tzeva_adom { const std::vector & get_alerts() const { return alerts; } std::vector & get_mutable_alerts() { return alerts; } void set_alerts(const std::vector & value) { this->alerts = value; } + + std::string get_cities() override { + return fmt::format("{}", fmt::join(get_cities_arr(), ", ")); + } + + std::vector get_cities_arr() override { + std::vector cities_to_return = {} ; + for (auto alert : alerts) { + cities_to_return.push_back(fmt::format("{}", fmt::join(alert.get_cities(), ""))); + } + return cities_to_return; + } + + std::vector get_alerts() override { + std::vector alertsToReturn {}; + for (IAlert alert : alerts) { + alertsToReturn.insert(alertsToReturn.begin(), alert); + } + return alertsToReturn; + }; }; using AlertResponse = std::vector; diff --git a/models/Interfaces/IAlert.cpp b/models/Interfaces/IAlert.cpp new file mode 100644 index 0000000..0be51c1 --- /dev/null +++ b/models/Interfaces/IAlert.cpp @@ -0,0 +1,16 @@ +// +// Created by yawaflua on 30/10/2024. +// +#pragma once +#include +#include + +namespace tzeva_adom { + class IAlert { + public: + virtual ~IAlert() = default; + + virtual std::vector get_cities() {}; + virtual int get_threat() {}; + }; +} \ No newline at end of file diff --git a/models/Interfaces/IAlertResponse.cpp b/models/Interfaces/IAlertResponse.cpp new file mode 100644 index 0000000..34c5a77 --- /dev/null +++ b/models/Interfaces/IAlertResponse.cpp @@ -0,0 +1,24 @@ +// +// Created by yawaflua on 30/10/2024. +// +#pragma once +#include +#include +#include "IAlert.cpp" + +namespace tzeva_adom { + class IAlertResponse + { + public: + // IAlertResponse() = default; + virtual ~IAlertResponse() = default; + + virtual int get_id() = 0; + virtual int get_threat() = 0; + virtual std::string get_cities() = 0; + virtual std::vector get_cities_arr() = 0; + virtual std::vector get_alerts() = 0; + + }; + +} \ No newline at end of file diff --git a/models/OrefAlertResponse.cpp b/models/OrefAlertResponse.cpp new file mode 100644 index 0000000..bddfb4d --- /dev/null +++ b/models/OrefAlertResponse.cpp @@ -0,0 +1,125 @@ +// +// Created by yawaflua on 30/10/2024. +// +#pragma once +#ifndef OREFALERTRESPONSE +#define OREFALERTRESPONSE + +#include "models/Interfaces/IAlertResponse.cpp" +#include "utils/OREFToTzevaAdom.cpp" +#include + +namespace tzeva_adom{ + + class OrefAlert : public IAlert { + public: + OrefAlert() = default; + //virtual ~OrefAlert() = default; + + void set_values(int _threat, std::vector _cities) { + this->cities = _cities; + this->threat = _threat; + } + + std::vector get_cities() override { return cities; } + int get_threat() override { return threat; } + + private: + int threat; + std::vector cities; + }; + + class OrefAlertResponse : public IAlertResponse { + public: + OrefAlertResponse(const std::string& alertDate, const std::string& title, + const std::string& data, int64_t threat) + : alert_date(alertDate), title(title), data(data), threat(threat) {} + virtual ~OrefAlertResponse() = default; + + private: + std::string alert_date; + std::string title; + std::string data; + int64_t threat; + + public: + + inline void set_data(std::string alert, std::string title_provided, std::string data_provided, int threat_provided) { + alert_date = alert; + title = title_provided; + data = data_provided; + threat = threat_provided; + } + + const std::string & get_alert_date() const { return alert_date; } + std::string & get_mutable_alert_date() { return alert_date; } + void set_alert_date(const std::string & value) { this->alert_date = value; } + + const std::string & get_title() const { return title; } + std::string & get_mutable_title() { return title; } + void set_title(const std::string & value) { this->title = value; } + + const std::string & get_data() const { return data; } + std::string & get_mutable_data() { return data; } + void set_data(const std::string & value) { this->data = value; } + + const int64_t &get_threat() const { return threat; } + int get_threat() override { return oref_threat_to_tzeva_adom(threat); } + int64_t & get_mutable_threat() { return threat; } + void set_threat(const int64_t & value) { this->threat = value; } + + int get_id() override { + std::tm t = {}; + std::istringstream ss(alert_date); + + if (ss >> std::get_time(&t, "%Y-%m-%d %H:%M:%S")) + { + return std::mktime(&t) % 1000000; + } + }; + + std::string get_cities() override {return data; }; + + std::vector get_cities_arr() override { return std::vector {data}; } + + std::vector get_alerts() override { + auto orefAlertReturn = new OrefAlert(); + orefAlertReturn->set_values(threat, get_cities_arr()); + IAlert iAlertToReturn = static_cast(std::ref(*orefAlertReturn)); + return std::vector {iAlertToReturn}; + }; + }; + + +} + + +namespace tzeva_adom { + // void from_json(const nlohmann::json & j, OrefAlertResponse & x); + // void to_json(nlohmann::json & j, const OrefAlertResponse & x); + + inline void to_json(nlohmann::json& j, const OrefAlertResponse& alert) { + j = nlohmann::json{ + {"alert_date", alert.get_alert_date()}, + {"title", alert.get_title()}, + {"data", alert.get_data()}, + {"threat", alert.get_threat()} + }; + } + + inline void from_json(const nlohmann::json& j, OrefAlertResponse& alert) { + if (j.contains("alert_date")) { + alert.set_alert_date(j.at("alert_date").get()); + } + if (j.contains("title")) { + alert.set_title(j.at("title").get()); + } + if (j.contains("data")) { + alert.set_data(j.at("data").get()); + } + if (j.contains("threat")) { + alert.set_threat(j.at("threat").get()); + } + } +} +#endif diff --git a/utils/OREFToTzevaAdom.cpp b/utils/OREFToTzevaAdom.cpp new file mode 100644 index 0000000..6078fac --- /dev/null +++ b/utils/OREFToTzevaAdom.cpp @@ -0,0 +1,26 @@ +// +// Created by yawaflua on 13/11/2024. +// +#pragma once + +#ifndef OREFTOTZEVAADOM_CPP +#define OREFTOTZEVAADOM_CPP + +namespace tzeva_adom { + inline int oref_threat_to_tzeva_adom(int threat) { + switch (threat) { + case 1: return 0; + case 2: return 5; + case 3: return 7; + case 4: return 8; + case 6: + case 7: return 3; + case 8: return 0; + case 9: return 5; + case 10: return 4; + case 11: return 6; + default: return 9; + } + } +} +#endif \ No newline at end of file