add update warn system => V3.0.0

This commit is contained in:
Markus 2019-10-04 20:11:01 +02:00
parent 61772afeb8
commit 43aff4b348
6 changed files with 70 additions and 5 deletions

View File

@ -267,6 +267,14 @@ std::string PageManager::upper_string(const std::string &str)
return upper;
}

size_t PageManager::getDate()
{
std::time_t now = std::time(nullptr);
struct tm *tm_now = localtime(&now);
return static_cast<size_t>( static_cast<double>(1900 + tm_now->tm_year) * 365.24220 +
static_cast<double>(tm_now->tm_mon +1) * 30.43685 + tm_now->tm_mday);
}

int PageManager::writeToFile(std::string path, std::string text)
{
if(path == "")

View File

@ -7,6 +7,7 @@
#include <sstream>
#include <unistd.h> // sleep
#include <algorithm>
#include <ctime> // std::time, localtime ...


struct Reply {
@ -39,6 +40,7 @@ public:
int counterContains(std::string text, std::string substring_with_prozent_i_for_number, int starte_mit_dieser_Zahl = 1);
std::string grep(std::string text, std::string substring, bool IgnoreCaseSensetifity = false);
std::string upper_string(const std::string& str);
size_t getDate();

int writeToFile(std::string path, std::string text);


View File

@ -37,6 +37,7 @@ int setPaths(Settings &settings)

settings.cookieFilePath = CacheDir + "S_New4_cookies";
settings.accountNumberPath = CacheDir + "Account_Number";
settings.lastUpdateDateFilePath = CacheDir + "LastUpdateDate";

settings.accountFilePath = SettingsDir + "Accounts";
settings.serienListPath = SettingsDir + "SerienListe";
@ -150,6 +151,7 @@ int loadDefaulOptions(Settings &settings)
ofs << "#default-maxThreads=0" << std::endl;
ofs << std::endl;
ofs << "#search-AchteAufGroßUndKleinschreibung=false" << std::endl;
ofs << "#search-UpdateWarnungNachTagen=10" << std::endl;


ofs.close();
@ -258,7 +260,15 @@ int loadDefaulOptions(Settings &settings)
if(settings.debugMode)
std::cout << " > Defaults: OutputFile: " << settings.outputFilePath << std::endl;

} else if (what == "") {
} else if (what == "search-UpdateWarnungNachTagen") {
if(!isNumber(data)) {
std::cout << " Error_Defaults: search-UpdateWarnungNachTagen: Wert ist keine Zahl." << std::endl;
return 228;
} else {
settings.updateWarningDays = atoi(data.c_str());
}
if(settings.debugMode)
std::cout << " > Defaults: search-UpdateWarnungNachTagen: " << settings.updateWarningDays << std::endl;

} else if (what == "") {


View File

@ -18,6 +18,7 @@
#include <limits.h> // PATH_MAX
#include <unistd.h> // readlink()


#ifdef _WIN32
#include <windows.h>
#endif
@ -43,12 +44,14 @@ struct Settings {
accountNumberPath= "/tmp/a_n",
cookieFilePath = "/tmp/S_New4_cookies",
serienListPath = "/tmp/SerienListe",
lastUpdateDateFilePath = "/tmp/lastUpdateDateFile",

defaultsFilePath = "/tmp/defaults",
proxy_ip = "127.0.0.1",
languages = "GerDub,GerSub,Eng",
genaueHoster = "",
version = "2.9.0",
defaultFileVersion="1.3",
version = "3.0.0",
defaultFileVersion="1.4",
outputFilePath = "",
default_checkPath = "",
default_Searchmuster = "S%Staffel%E%Folge%";
@ -63,7 +66,8 @@ struct Settings {
startSeason = 1,
stopSeason = 0,
proxy_port = 9050,
default_maxDirs = 20;
default_maxDirs = 20,
updateWarningDays = 10;
char pathSymbol = '/';
unsigned maxThreads = 0;


View File

@ -156,6 +156,29 @@ int ProgramManager::sucheNach_1_Serien(Settings *settings, PageManager &pageMana
return 0;
}

int ProgramManager::checkLastUpdate(Settings *settings)
{
if(settings->updateWarningDays == 0)
return 0;

std::ifstream ifs(settings->lastUpdateDateFilePath);
if(!ifs.is_open()) {
perror(("Konnte die Datei '" + settings->lastUpdateDateFilePath + "' nicht öffnen").c_str());
return 1;
}
std::string line;
if(!std::getline(ifs, line).good()) {
perror("GetLine from Date failed");
return 2;

} else if( ( static_cast<long long>(pageManager.getDate()) - atoll(line.c_str()) ) >= settings->updateWarningDays) {
std::cout << ((settings->colorless) ? "" : "\033[93m") << " => Warnung: SerienListe zuletzt vor " << settings->updateWarningDays << " Tagen aktualisiert."
<< std::endl << " Mit '" << settings->programName << " search -u' kannst du die Liste aktualisieren." << "\033[0m" << std::endl;;
}

return 0;
}

int ProgramManager::defaultModus(Settings *settings)
{
AccountManager accountManager(settings->accountFilePath, settings->accountNumberPath);
@ -389,7 +412,7 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)

std::ifstream ifs(settings->serienListPath);
if(!ifs.is_open()) {
std::cout << "Keine SerienListe vorhanden. Erstelle eine neue..." << std::endl;
std::cout << " => Keine SerienListe vorhanden. Erstelle eine neue..." << std::endl;
if(searchModus_update(settings) != 0)
return 354;
else {
@ -402,6 +425,10 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo)
}
}

//Check for last Update..
if(checkLastUpdate(settings) != 0)
return -1;

//Save file in string:
std::string serienListe((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

@ -789,6 +816,19 @@ int ProgramManager::searchModus_update(Settings *settings)
}

std::cout << ((settings->colorless) ? "" : "\033[93m") << "Serienunterschied: " << ( ((countAf - countBef) > 0) ? "+" : "") << countAf - countBef << " Serien." << "\033[0m" << std::endl;

//Speicher Dateim des Updates...
ofs.open(settings->lastUpdateDateFilePath, std::ios::trunc);
if(!ofs.is_open()) {
perror("Konnte UpdateDate-Datei nicht öffnen");
return 113;
} else {
//Schreibe Liste in das TextFile
ofs << pageManager.getDate() << std::endl;
ofs.close();
}


return 0;
}


View File

@ -56,6 +56,7 @@ private:
int searchModus_update(Settings * settings);
int waitForThreads();
int sucheNach_1_Serien(Settings *settings, PageManager &pageManager, std::string &newName);
int checkLastUpdate(Settings * settings);


};