From e695a65df9d5a8ee7d5af705c4789e44fbcc0b60 Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Sun, 10 May 2026 19:33:01 +0500 Subject: Config support --- src/main.cpp | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index f936e85..b7ff89a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,21 +1,41 @@ #include "RSS.hpp" #include -#include +#include +#include +#include + +#define CONFIG_LOCATION std::getenv("HOME") + "/.config/rsshit.xml" +// #define CONFIG_LOCATION "rsshit.xml" + +std::string read_config() { + std::ifstream file(std::string(std::getenv("HOME")) + "/.config/rsshit.xml"); + std::stringstream buffer; + buffer << file.rdbuf(); + + return buffer.str(); +} int main() { - // auto tmp = RSS_leaf::TokenizeXML(" abc "); - auto rss = std::make_unique("https://www.independent.co.uk/news/uk/rss"); - rss->channelInfo.print(); - int i = 0; - for (auto entry : rss->Entries) { - if (i > 3) break; - entry.print(); - ++i; + std::string config; + try { + config = read_config(); + if (config.length() == 0) { + std::cout << "failed to read config file: the file is empty" << std::endl; + return 1; + } + XML_leaf configParsed(config); + auto sources = configParsed.GetChildren("source"); + for (auto src : sources) { + std::cout << "URL: " << src.GetValue() << std::endl; + RSS(src.GetValue()).print(); + } + } catch (char *ex) { + std::cout << "failed to read config file: " << ex << std::endl; + return 1; } - // auto rss_1 = std::make_unique("https://feeds.washingtonpost.com/rss/world"); - // auto rss_2 = std::make_unique("https://news.yahoo.com/rss/mostviewed"); - // for (auto entry : rss_2->Entries) - // entry.print(); + + // RSS("https://www.independent.co.uk/news/uk/rss").print(); + // RSS("https://news.yahoo.com/rss/mostviewed").print(); return 0; } -- cgit v1.3