download modules

This commit is contained in:
leca 2025-03-26 20:08:44 +03:00
parent 3b26dbc29d
commit 7a52905cff
10 changed files with 48 additions and 16 deletions

View File

@ -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);

View File

@ -5,5 +5,6 @@
<file>assets/icons/OFD.svg</file>
<file>assets/icons/icon.png</file>
<file>assets/icons/icon.svg</file>
<file>assets/icons/settings.svg</file>
</qresource>
</RCC>

View File

@ -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 )",

View File

@ -16,7 +16,7 @@ std::vector<std::string> 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<std::string> StoreModule::parse_net_weight(std::vector<std::string>
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;

View File

@ -101,7 +101,7 @@ std::vector<std::string> 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;

View File

@ -133,7 +133,17 @@
</sizepolicy>
</property>
<property name="text">
<string>Settings</string>
<string/>
</property>
<property name="icon">
<iconset resource="../build/Desktop-Debug/media.qrc">
<normaloff>:/icons/assets/icons/settings.svg</normaloff>:/icons/assets/icons/settings.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
</widget>
</item>

View File

@ -215,11 +215,6 @@
<source>Optical Character Recognition</source>
<translation>Optical Character Recognition</translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="136"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="43"/>
<source>Text from E-Mail</source>

View File

@ -215,11 +215,6 @@
<source>Optical Character Recognition</source>
<translation>Оптическое распознавание символов</translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="136"/>
<source>Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../scenes/mainwindow.ui" line="43"/>
<source>Text from E-Mail</source>

View File

@ -21,6 +21,9 @@
#include <QWidget>
#include <fstream>
#include <boost/regex.hpp>
#include <net/net.h>
#include <parser/parser.h>
#include <settings/settings.h>
#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<std::string> 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));
}
}

View File

@ -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