summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/RSS.cpp10
-rw-r--r--src/RSS.hpp5
-rw-r--r--src/main.cpp46
3 files changed, 46 insertions, 15 deletions
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;
}