From 7a52905cffd651871e9ff11e635303c0fbb93c23 Mon Sep 17 00:00:00 2001 From: leca Date: Wed, 26 Mar 2025 20:08:44 +0300 Subject: [PATCH] download modules --- main.cpp | 6 ++++++ media.qrc | 1 + modules/pyaterochka.json | 2 +- parser/module.cpp | 4 ++-- parser/parser.cpp | 2 +- scenes/mainwindow.ui | 12 +++++++++++- translations/en_US.ts | 5 ----- translations/ru_RU.ts | 5 ----- utils/utils.cpp | 25 +++++++++++++++++++++++++ utils/utils.h | 2 +- 10 files changed, 48 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index a6dac04..36435bc 100644 --- a/main.cpp +++ b/main.cpp @@ -41,7 +41,13 @@ static QWidget *loadUI(QWidget *parent, std::string filename) { } int main(int argc, char *argv[]) { + curl_global_init(CURL_GLOBAL_ALL); + + std::string program_data_path = get_path_relative_to_home(".local/share/checks_parser"); + create_directories(program_data_path); + srand(time(0)); + fetch_and_download_modules(); QApplication app(argc, argv); diff --git a/media.qrc b/media.qrc index 66caa1c..de5008e 100644 --- a/media.qrc +++ b/media.qrc @@ -5,5 +5,6 @@ assets/icons/OFD.svg assets/icons/icon.png assets/icons/icon.svg + assets/icons/settings.svg diff --git a/modules/pyaterochka.json b/modules/pyaterochka.json index 62b6b23..29f3796 100644 --- a/modules/pyaterochka.json +++ b/modules/pyaterochka.json @@ -1,6 +1,6 @@ { "name":"Пятёрочка", - "goods_name_regex": "^\\d+\\s\\t[\\(\\)\\%\\*a-zA-Z0-9\\u0401\\u0451\\u0410-\\u044f \\.\\-\\/]+", + "goods_name_regex": "^\\d+\\s\\t\\*?[\\(\\)\\%\\*a-zA-Z0-9ёЁА-я\\.\\-\\/ ]+", "goods_price_regex": "[0-9]{0,4}[^%]\\.[0-9]{2} ", "goods_net_weight_regex": "((\\d+(\\.|,)?\\d{0,}((м|)л|(к|м|)г|т|ц|шт|(pc|)s|(m|k|)g|(m|)l|t))(\\s|\\t){0,})+", "goods_quantity_regex": "([0-9]{0,4}[^%]\\.[0-9]{3} )|(\t\\d )", diff --git a/parser/module.cpp b/parser/module.cpp index 614934d..d7319ae 100644 --- a/parser/module.cpp +++ b/parser/module.cpp @@ -16,7 +16,7 @@ std::vector StoreModule::parse(std::wstring str, std::wstring regex std::cout << "Handling: " << to_utf8(str) << std::endl; for (boost::wsregex_iterator it{str.begin(), str.end(), r}, end{}; it != end; it++) { - std::wcout << "Parsed" << it->str() << std::endl; + std::wcout << "Parsed: " << it->str() << std::endl; result.push_back(to_utf8(it->str())); } @@ -52,7 +52,7 @@ std::vector StoreModule::parse_net_weight(std::vector result.push_back("?"); } else { result.push_back(parsed[0]); - name.erase(0, name.find(parsed[0]) + parsed[0].length()); + name.erase(name.find(parsed[0]), name.find(parsed[0]) + parsed[0].length()); } } return result; diff --git a/parser/parser.cpp b/parser/parser.cpp index d72e5ee..cc53510 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -101,7 +101,7 @@ std::vector Parser::check_updates() { for (const auto& file : directory_iterator(path)) { if (!is_regular_file(file)) continue; stored_modules.push_back(file.path().filename()); - std::cout << file.path().filename() << " detected store module" << std::endl; + std::cout << file.path().filename() << " detected local store module" << std::endl; } Net n; std::cerr << "Downloading modules list from: " << s.get_setting("stores_modules_url") << std::endl; diff --git a/scenes/mainwindow.ui b/scenes/mainwindow.ui index dc48141..360223f 100644 --- a/scenes/mainwindow.ui +++ b/scenes/mainwindow.ui @@ -133,7 +133,17 @@ - Settings + + + + + :/icons/assets/icons/settings.svg:/icons/assets/icons/settings.svg + + + + 128 + 128 + diff --git a/translations/en_US.ts b/translations/en_US.ts index 6eeca82..f225df2 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -215,11 +215,6 @@ Optical Character Recognition Optical Character Recognition - - - Settings - - Text from E-Mail diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index b246546..d7c7735 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -215,11 +215,6 @@ Optical Character Recognition Оптическое распознавание символов - - - Settings - - Text from E-Mail diff --git a/utils/utils.cpp b/utils/utils.cpp index ab01d21..8e790e6 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #ifdef BUILD_OFD_BINARYEYE_SCAN @@ -307,3 +310,25 @@ void generate_qr_code(std::string data) { } #endif // ifdef BUILD_OFD_BINARYEYE_SCAN + +void fetch_and_download_modules() { + Net n; + Parser p; + std::string settings_file_path = get_path_relative_to_home(".local/share/checks_parser/settings.json"); + + Settings s(settings_file_path); + + std::vector storesUpdates = p.check_updates(); + for (auto &update : storesUpdates) { + std::cout << "Downloading " + << s.get_setting("stores_modules_url") + update << " to " + << get_path_relative_to_home(s.get_setting("stores_modules_dir") + + "/" + update) + << std::endl; + + n.get_file(s.get_setting("stores_modules_url") + "/" + update, + get_path_relative_to_home(s.get_setting("stores_modules_dir") + + "/" + update)); + + } +} diff --git a/utils/utils.h b/utils/utils.h index 7946b2a..acc6acd 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -30,6 +30,6 @@ void generate_qr_code(std::string data); std::string get_local_ip_address(); #endif - +void fetch_and_download_modules(); #endif // UTILS_H