summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-05-10 20:58:10 +0500
committerPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-05-10 20:58:10 +0500
commit600edb6b68173ae931aaa88d74573964d5306224 (patch)
tree7556c25de1aa1a39fe42fcff1a147ec2d85449e4
parent92bee957b4face63285933f48f6d6e04ac064ca8 (diff)
Better error handling
-rw-r--r--.gitignore2
-rwxr-xr-xnewsbin702280 -> 702152 bytes
-rw-r--r--src/RSS.cpp24
3 files changed, 17 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 6db993a..4327969 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1 @@
-app
+news
diff --git a/news b/news
index c6c2332..a0eabba 100755
--- a/news
+++ b/news
Binary files differ
diff --git a/src/RSS.cpp b/src/RSS.cpp
index 93c391d..20c809f 100644
--- a/src/RSS.cpp
+++ b/src/RSS.cpp
@@ -48,18 +48,24 @@ std::string RSS::request() {
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &data);
curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(curl.get(), CURLOPT_CONNECTTIMEOUT, 2L);
- auto res = curl_easy_perform(curl.get());
- if (res != CURLE_OK) {
- throw std::runtime_error(std::string("CURL request failed: ") + curl_easy_strerror(res));
- }
+ try {
+ auto res = curl_easy_perform(curl.get());
+ if (res != CURLE_OK) {
+ // throw std::runtime_error(std::string("CURL request failed: ") + curl_easy_strerror(res));
+ return "";
+ }
- curl_easy_cleanup(curl.get());
- return data;
+ return data;
+ } catch (const std::exception& e) {
+ return "";
+ }
}
void RSS::parse(std::string contents) {
// std::cout << "starting tokenization..." << std::endl;
+ if (contents.length() == 0) return;
try {
auto leaf = XML_leaf(contents).GetChild("channel");
if (leaf.Raw == "<>")
@@ -91,6 +97,8 @@ void RSS::print_latest(int minutesSpan) {
std::tm* gmt_time = std::gmtime(&now);
gmt_time->tm_min -= minutesSpan;
auto ticks = std::mktime(gmt_time);
+ // std::cout << "starting time: " << std::put_time(gmt_time, "%Y-%m-%d %H:%M:%S") << std::endl;
+
for (auto entry : Entries) {
if (entry.pubDate.tm_year == 0 || std::mktime(&entry.pubDate) < ticks) break;
@@ -110,10 +118,10 @@ RSS_Entry::RSS_Entry(XML_leaf node) {
void RSS_Entry::print() {
std::cout
- << Title << '\n'
+ << "\033[1m" << Title << "\033[0m" << '\n'
<< std::put_time(&pubDate, "%Y-%m-%d %H:%M:%S") << '\n'
<< Contents << '\n'
- << URL<< '\n'
+ << URL << '\n'
<< "==============================\n";
}