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
---
README.md | 2 ++
rsshit.xml | 4 ++++
src/RSS.cpp | 10 ++++++++++
src/RSS.hpp | 5 +++--
src/main.cpp | 46 +++++++++++++++++++++++++++++++++-------------
5 files changed, 52 insertions(+), 15 deletions(-)
create mode 100644 README.md
create mode 100644 rsshit.xml
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 @@
+
+
+
+
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
#include
#include
-#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 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
-#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