a lot of fixes
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
#include "parser.h"
|
||||
#include "../settings.h"
|
||||
#include "../goods/goods.h"
|
||||
#include "../net/net.h"
|
||||
#include "../settings/settings.h"
|
||||
#include "../utils/utils.h"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "../goods/goods.h"
|
||||
|
||||
Parser::Parser() {}
|
||||
|
||||
std::vector<std::string> Parser::search_modules() {
|
||||
std::string path = std::string(std::getenv("HOME")) + "/" + STORES_MODULES_DIR;
|
||||
Settings s(get_path_relative_to_home(".local/share/checks_parser/settings.json"));
|
||||
std::string path = get_path_relative_to_home(s.get_setting("stores_modules_dir"));//std::string(std::getenv("HOME")) + "/" + STORES_MODULES_DIR;
|
||||
std::filesystem::directory_entry modules_dir(path);
|
||||
|
||||
if (!modules_dir.exists()) {
|
||||
@@ -38,9 +41,7 @@ std::vector<Goods> Parser::parse(std::wstring check_plaintext) {
|
||||
std::vector<std::string> goods_prices = module.parse_price(check_plaintext);
|
||||
std::vector<std::string> goods_quantities =
|
||||
module.parse_quantity(check_plaintext);
|
||||
#ifdef DEBUG
|
||||
std::cout << goods_names.size() << " " << goods_prices.size() << " " << goods_quantities.size() << std::endl;
|
||||
#endif
|
||||
|
||||
if (goods_names.size() != goods_prices.size() ||
|
||||
goods_names.size() != goods_quantities.size() ||
|
||||
goods_prices.size() != goods_quantities.size()) {
|
||||
@@ -57,3 +58,38 @@ std::vector<Goods> Parser::parse(std::wstring check_plaintext) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> Parser::check_updates() {
|
||||
std::cout << "Checking updates for stores modules" << std::endl;
|
||||
Settings s(get_path_relative_to_home(".local/share/checks_parser/settings.json"));
|
||||
std::string path = get_path_relative_to_home(s.get_setting("stores_modules_dir"));
|
||||
|
||||
std::vector<std::string> to_download;
|
||||
std::vector<std::string> stored_modules;
|
||||
|
||||
std::filesystem::directory_entry modules_dir(path);
|
||||
if (!modules_dir.exists()) {
|
||||
std::filesystem::create_directories(path);
|
||||
}
|
||||
for (const auto& file : std::filesystem::directory_iterator(path)) {
|
||||
if (!file.is_regular_file()) continue;
|
||||
stored_modules.push_back(file.path().filename());
|
||||
std::cout << file.path().filename() << " detected store module" << std::endl;
|
||||
}
|
||||
Net n;
|
||||
std::cerr << "Downloading modules list from: " << s.get_setting("stores_modules_url");
|
||||
std::vector<std::string> remote_modules = n.get_all_modules(s.get_setting("stores_modules_url"));
|
||||
if (stored_modules.empty()) {
|
||||
std::cout << "I need to download everything" << std::endl;
|
||||
to_download = remote_modules;
|
||||
} else {
|
||||
for (const std::string& module : remote_modules) {
|
||||
if (!vector_contains_element(stored_modules, module)) {
|
||||
std::cout << "I need to download store module " << module << std::endl;
|
||||
to_download.push_back(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return to_download;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#include "../goods/goods.h"
|
||||
#include "module.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../goods/goods.h"
|
||||
|
||||
class Parser {
|
||||
|
||||
StoreModule module;
|
||||
|
||||
public:
|
||||
Parser();
|
||||
|
||||
std::vector<std::string> search_modules();
|
||||
|
||||
std::vector<std::string> check_updates();
|
||||
|
||||
void set_module(std::string);
|
||||
|
||||
std::vector<Goods> parse (std::wstring);
|
||||
std::vector<Goods> parse(std::wstring);
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
||||
Reference in New Issue
Block a user