From 696ea1ff579604f1c91432b86e132ad0448c375c Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 11 Mar 2018 15:12:10 +0100 Subject: [PATCH] Changed behaviour when last entry is not in current feed --- CMakeLists.txt | 2 +- src/mastorss.cpp | 6 ++++++ src/parse.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1581351..0594b4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastorss - VERSION 0.3.4 + VERSION 0.3.5 LANGUAGES CXX ) diff --git a/src/mastorss.cpp b/src/mastorss.cpp index 43218b2..ee43cfc 100644 --- a/src/mastorss.cpp +++ b/src/mastorss.cpp @@ -113,6 +113,12 @@ int main(int argc, char *argv[]) std::this_thread::sleep_for(std::chrono::seconds(2)); } + // If the last entry is not in the current feed, set the oldest item as last entry + // Could lead to spamming if an item gets deleted or changed. + if (!new_content) + { + config.put(profile + ".last_entry", entries.at(entries.size() - 1)); + } pt::write_json(filepath + "config-" + profile + ".json", config); return 0; diff --git a/src/parse.cpp b/src/parse.cpp index 87a1e0e..438ce4f 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -121,7 +121,7 @@ std::vector parse_website(const string &profile, const string &xml) string str = title + "\n\n" + desc; // ANF News puts this always on top, causing us to think it's new - if (title.compare("Newsticker zu den Angriffen auf Efrîn ") == 0) + if (title.compare(0, 35, "Newsticker zu den Angriffen auf Efr") == 0) { continue; } @@ -147,8 +147,8 @@ std::vector parse_website(const string &profile, const string &xml) str = std::regex_replace(str, reindyfuckup, ""); str = std::regex_replace(str, redaclosing, ""); str = std::regex_replace(str, reggboclosing, ""); - str = std::regex_replace(str, std::regex("[\\r\\n] [\\r\\n]"), "\n\n"); // remove space between newlines - str = std::regex_replace(str, std::regex("[\\r\\n]{3,}"), "\n"); // remove excess newlines + str = std::regex_replace(str, std::regex("[\\r\\n] +[\\r\\n]"), "\n\n"); // remove space between newlines + str = std::regex_replace(str, std::regex("[\\r\\n]{3,}"), "\n"); // remove excess newlines for (const string &hashtag : watchwords) { @@ -162,7 +162,7 @@ std::vector parse_website(const string &profile, const string &xml) if ((str.size() + link.size()) > (std::uint16_t)(max_size - 15)) { str.resize((max_size - link.size() - 15)); - str.resize(str.rfind(' ')); + str.resize(str.rfind(' ')); // Cut at word boundary str += " […]"; } str += "\n\n" + link + "\n\n#bot";