diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-05-10 19:33:01 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-05-10 19:33:01 +0500 |
| commit | e695a65df9d5a8ee7d5af705c4789e44fbcc0b60 (patch) | |
| tree | b86aaafa8c549f381bd9f76d23174b169b1ce792 | |
| parent | a14878b4a453f48f3b200481c343a7fc59181b0f (diff) | |
Config support
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | rsshit.xml | 4 | ||||
| -rw-r--r-- | src/RSS.cpp | 10 | ||||
| -rw-r--r-- | src/RSS.hpp | 5 | ||||
| -rw-r--r-- | src/main.cpp | 46 |
5 files changed, 52 insertions, 15 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f51de8 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# CONFIG +To get an initial config copt the `rsshit.xml` to ~/.config diff --git a/rsshit.xml b/rsshit.xml new file mode 100644 index 0000000..7b54889 --- /dev/null +++ b/rsshit.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<config> + <source> <![CDATA[https://www.independent.co.uk/news/uk/rss]]> </source> +</config> diff --git a/src/RSS.cpp b/src/RSS.cpp index 275b96c..1282c83 100644 --- a/src/RSS.cpp +++ b/src/RSS.cpp @@ -76,6 +76,16 @@ void RSS::parse(std::string contents) { } } +void RSS::print() { + channelInfo.print(); + int i = 0; + for (auto entry : Entries) { + if (i > 3) break; + entry.print(); + ++i; + } +} + RSS_Entry::RSS_Entry(XML_leaf node) { Title = node.GetChild("title").GetValue(); URL = node.GetChild("link").GetValue(); diff --git a/src/RSS.hpp b/src/RSS.hpp index 1394842..1ff2bc7 100644 --- a/src/RSS.hpp +++ b/src/RSS.hpp @@ -12,7 +12,6 @@ #include <utility> #include <variant> #include <vector> -#include "DateUtils.hpp" class XML_leaf { public: @@ -106,8 +105,9 @@ class XML_leaf { } static std::string trimSpaces(std::string raw) { - auto outp = std::regex_replace(raw, std::regex(" +"), " "); + auto outp = std::regex_replace(raw, std::regex("\n"), ""); outp = std::regex_replace(outp, std::regex("> <"), "><"); + outp = std::regex_replace(outp, std::regex(" +"), " "); return outp; } @@ -214,6 +214,7 @@ class RSS { std::vector<RSS_Entry> Entries = {}; RSS(std::string url); + void print(); private: std::string request(); 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 <curl/curl.h> -#include <memory> +#include <fstream> +#include <iostream> +#include <string> + +#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("<test> abc </test>"); - auto rss = std::make_unique<RSS>("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<RSS>("https://feeds.washingtonpost.com/rss/world"); - // auto rss_2 = std::make_unique<RSS>("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; } |
