diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-05-10 19:55:02 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-05-10 19:55:02 +0500 |
| commit | 92bee957b4face63285933f48f6d6e04ac064ca8 (patch) | |
| tree | 00f8b7ae6033165d767c1e371d3a8ce880766e86 | |
| parent | e695a65df9d5a8ee7d5af705c4789e44fbcc0b60 (diff) | |
Time sorting
| -rw-r--r-- | Makefile | 2 | ||||
| -rwxr-xr-x | news | bin | 0 -> 702280 bytes | |||
| -rw-r--r-- | rsshit.xml | 1 | ||||
| -rw-r--r-- | src/RSS.cpp | 17 | ||||
| -rw-r--r-- | src/RSS.hpp | 1 | ||||
| -rw-r--r-- | src/main.cpp | 8 |
6 files changed, 24 insertions, 5 deletions
@@ -2,4 +2,4 @@ SOURCEFILES := src/main.cpp src/RSS.cpp GPPFLAGS := -Wall -Wextra -std=c++23 all: - g++ $(GPPFLAGS) $(SOURCEFILES) -lcurl -o app + g++ $(GPPFLAGS) $(SOURCEFILES) -lcurl -o news Binary files differ@@ -1,4 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <config> + <lastminutes> 60 </lastminutes> <source> <![CDATA[https://www.independent.co.uk/news/uk/rss]]> </source> </config> diff --git a/src/RSS.cpp b/src/RSS.cpp index 1282c83..93c391d 100644 --- a/src/RSS.cpp +++ b/src/RSS.cpp @@ -86,6 +86,18 @@ void RSS::print() { } } +void RSS::print_latest(int minutesSpan) { + std::time_t now = std::time(nullptr); + std::tm* gmt_time = std::gmtime(&now); + gmt_time->tm_min -= minutesSpan; + auto ticks = std::mktime(gmt_time); + + for (auto entry : Entries) { + if (entry.pubDate.tm_year == 0 || std::mktime(&entry.pubDate) < ticks) break; + entry.print(); + } +} + RSS_Entry::RSS_Entry(XML_leaf node) { Title = node.GetChild("title").GetValue(); URL = node.GetChild("link").GetValue(); @@ -98,9 +110,10 @@ RSS_Entry::RSS_Entry(XML_leaf node) { void RSS_Entry::print() { std::cout - << "==============================\n" << Title << '\n' << std::put_time(&pubDate, "%Y-%m-%d %H:%M:%S") << '\n' << Contents << '\n' - << URL<< '\n'; + << URL<< '\n' + << "==============================\n"; } + diff --git a/src/RSS.hpp b/src/RSS.hpp index 1ff2bc7..5dd8376 100644 --- a/src/RSS.hpp +++ b/src/RSS.hpp @@ -215,6 +215,7 @@ class RSS { RSS(std::string url); void print(); + void print_latest(int minutesSpan); private: std::string request(); diff --git a/src/main.cpp b/src/main.cpp index b7ff89a..cabe6dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,10 +24,14 @@ int main() { return 1; } XML_leaf configParsed(config); + + auto span = std::stoi(configParsed.GetChild("lastminutes").GetValue()); + std::cout << "News of the last " << span << " minutes:" << std::endl; + auto sources = configParsed.GetChildren("source"); for (auto src : sources) { - std::cout << "URL: " << src.GetValue() << std::endl; - RSS(src.GetValue()).print(); + // std::cout << "URL: " << src.GetValue() << std::endl; + RSS(src.GetValue()).print_latest(span); } } catch (char *ex) { std::cout << "failed to read config file: " << ex << std::endl; |
