From 95a4d9cc81406cf0dadf50e866d3fc2de454b53c Mon Sep 17 00:00:00 2001 From: Clortox Date: Fri, 23 Jul 2021 23:24:20 -0400 Subject: [PATCH] Display feed info from cli options --- src/main.cpp | 11 +++++----- src/options.hpp | 4 +++- src/rss.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++ src/rss_out.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ src/rss_out.hpp | 19 +++++++++++++++++ 5 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 src/rss_out.cpp create mode 100644 src/rss_out.hpp diff --git a/src/main.cpp b/src/main.cpp index c0d191e..d377dce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include "config.hpp" +#include "rss_out.hpp" #include "options.hpp" #include "rss.hpp" @@ -31,13 +32,11 @@ int main(int argc, char** argv) { exit(-1); //display requested attributes + std::string output = rss_utils::rss_to_list(feed, opts); + + std::cout << output << std::endl; - - - - - - + delete opts; return 0; } diff --git a/src/options.hpp b/src/options.hpp index d17ae26..877dd4b 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -4,12 +4,14 @@ // options parsing // +#pragma once + #include #include #include //cli options -constexpr char* optarg_string = "u:tldemcpqgowbh"; +constexpr char optarg_string[] = "u:tldemcpqgowbh"; static struct option long_options[] = { diff --git a/src/rss.cpp b/src/rss.cpp index 1865c1f..e463352 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -170,6 +170,57 @@ std::string rss::getPubDate() const { } +std::string rss::getManagingEditor() const { + if(!ok) + return ""; + + rapidxml::xml_node<> *tmp = item_node->first_node("managingEditor"); + if(tmp == 0) + return ""; + return tmp->value(); +} + +std::string rss::getGenerator() const { + if(!ok) + return ""; + + rapidxml::xml_node<> *tmp = item_node->first_node("generator"); + if(tmp == 0) + return ""; + return tmp->value(); +} + +std::string rss::getDocs() const { + if(!ok) + return ""; + + rapidxml::xml_node<> *tmp = item_node->first_node("docs"); + if(tmp == 0) + return ""; + return tmp->value(); +} + +std::string rss::getTTL() const { + if(!ok) + return ""; + + rapidxml::xml_node<> *tmp = item_node->first_node("ttl"); + if(tmp == 0) + return ""; + return tmp->value(); + +} + +std::string rss::getLastBuildDate() const { + if(!ok) + return ""; + + rapidxml::xml_node<> *tmp = item_node->first_node("lastBuildDate"); + if(tmp == 0) + return ""; + return tmp->value(); +} + std::vector> rss::getItems() const { std::vector> items; diff --git a/src/rss_out.cpp b/src/rss_out.cpp new file mode 100644 index 0000000..d460f8f --- /dev/null +++ b/src/rss_out.cpp @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 7-23-21 +// rss output functions implementation +// + +#include "rss_out.hpp" + +using namespace rss_utils; + +std::string rss_utils::rss_to_list(const rss& rss_obj, const option_flags* flags){ + std::string ret; + + if(flags->title){ + ret += rss_obj.getTitle() + "\n"; + } + if(flags->link){ + ret += rss_obj.getLink() + "\n"; + } + if(flags->description){ + ret += rss_obj.getDescription() + "\n"; + } + if(flags->language){ + ret += rss_obj.getLanguage() + "\n"; + } + if(flags->webmaster){ + ret += rss_obj.getWebMaster() + "\n"; + } + if(flags->copyright){ + ret += rss_obj.getCopyright() + "\n"; + } + if(flags->pubdate){ + ret += rss_obj.getPubDate() + "\n"; + } + if(flags->managingeditor){ + ret += rss_obj.getManagingEditor() + "\n"; + } + if(flags->generator){ + ret += rss_obj.getGenerator() + "\n"; + } + if(flags->docs){ + ret += rss_obj.getDocs() + "\n"; + } + if(flags->ttl){ + ret += rss_obj.getTTL() + "\n"; + } + if(flags->builddate){ + ret += rss_obj.getLastBuildDate() + "\n"; + } + + if(ret.length() > 0) + ret.pop_back(); + else if (ret.length() == 0) + ret = ""; + + return ret; +} diff --git a/src/rss_out.hpp b/src/rss_out.hpp new file mode 100644 index 0000000..23c8f19 --- /dev/null +++ b/src/rss_out.hpp @@ -0,0 +1,19 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 7-23-21 +// rss output functions +// + +#pragma once + +#include + +#include "options.hpp" +#include "rss.hpp" + +namespace rss_utils { + std::string rss_to_list(const rss&, const option_flags*); + + + +}