Display feed info from cli options

This commit is contained in:
Clortox 2021-07-23 23:24:20 -04:00
parent b0783ea304
commit 95a4d9cc81
5 changed files with 135 additions and 7 deletions

View File

@ -9,6 +9,7 @@
#include <getopt.h>
#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;
}

View File

@ -4,12 +4,14 @@
// options parsing
//
#pragma once
#include <string>
#include <iostream>
#include <getopt.h>
//cli options
constexpr char* optarg_string = "u:tldemcpqgowbh";
constexpr char optarg_string[] = "u:tldemcpqgowbh";
static struct option long_options[] =
{

View File

@ -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<std::map<std::string, std::string>> rss::getItems() const {
std::vector<std::map<std::string, std::string>> items;

57
src/rss_out.cpp Normal file
View File

@ -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 = "<No arguments given>";
return ret;
}

19
src/rss_out.hpp Normal file
View File

@ -0,0 +1,19 @@
///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 7-23-21
// rss output functions
//
#pragma once
#include <string>
#include "options.hpp"
#include "rss.hpp"
namespace rss_utils {
std::string rss_to_list(const rss&, const option_flags*);
}