From 8bfd9218cb530bb83edb1d04d24616d31f920382 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 28 Dec 2019 07:13:56 +0100 Subject: [PATCH] Post new items. --- src/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cb30232..f6c4d60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,30 @@ #include "config.hpp" #include "document.hpp" #include "exceptions.hpp" +#include "mastoapi.hpp" #include "version.hpp" #include #include #include +#include #include #include #include #include +#include #include using namespace mastorss; +using std::chrono::seconds; using std::getenv; using std::cout; using std::cerr; using std::runtime_error; using std::string_view; using std::vector; +using std::this_thread::sleep_for; namespace mastorss { @@ -94,9 +99,19 @@ int main(int argc, char *argv[]) Document doc{cfg}; doc.parse(); - for (const auto &item : doc.new_items) + MastoAPI masto{cfg.data}; + if (!doc.new_items.empty()) { - cout << "--\n" << item.description.substr(0, 200) << "\n"; + for (const auto &item : doc.new_items) + { + masto.post_item(item); + cfg.data.last_guid = item.guid; + if (item != *doc.new_items.rbegin()) + { // Don't sleep if this is the last item. + sleep_for(seconds(cfg.data.interval)); + } + } + cfg.write(); } } catch (const FileException &e)