2019-12-20 01:14:23 +01:00
|
|
|
/* This file is part of mastorss.
|
2020-11-21 22:30:24 +01:00
|
|
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
2019-12-20 01:14:23 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MASTORSS_DOCUMENT_HPP
|
|
|
|
#define MASTORSS_DOCUMENT_HPP
|
|
|
|
|
2019-12-25 02:08:53 +01:00
|
|
|
#include "config.hpp"
|
2020-11-21 22:30:24 +01:00
|
|
|
#include "curl_wrapper.hpp"
|
2019-12-25 02:08:53 +01:00
|
|
|
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
2019-12-28 06:48:35 +01:00
|
|
|
#include <list>
|
2020-11-21 22:30:24 +01:00
|
|
|
#include <string>
|
2019-12-20 01:14:23 +01:00
|
|
|
|
|
|
|
namespace mastorss
|
|
|
|
{
|
2019-12-25 02:08:53 +01:00
|
|
|
namespace pt = boost::property_tree;
|
2019-12-28 06:48:35 +01:00
|
|
|
using std::list;
|
2020-11-21 22:30:24 +01:00
|
|
|
using std::string;
|
2019-12-20 01:14:23 +01:00
|
|
|
|
2019-12-25 02:08:53 +01:00
|
|
|
/*!
|
|
|
|
* @brief An Item of a feed.
|
|
|
|
*
|
|
|
|
* @since 0.10.0
|
|
|
|
*/
|
|
|
|
struct Item
|
|
|
|
{
|
|
|
|
string description;
|
|
|
|
string guid;
|
|
|
|
string link;
|
|
|
|
string title;
|
2019-12-28 07:12:28 +01:00
|
|
|
|
2020-11-21 22:30:24 +01:00
|
|
|
friend bool operator!=(const Item &a, const Item &b);
|
2019-12-25 02:08:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief A feed.
|
|
|
|
*
|
|
|
|
* @since 0.10.0
|
|
|
|
*/
|
2019-12-20 01:14:23 +01:00
|
|
|
class Document
|
|
|
|
{
|
|
|
|
public:
|
2019-12-25 06:26:20 +01:00
|
|
|
explicit Document(Config &cfg);
|
2019-12-20 01:14:23 +01:00
|
|
|
Document(const Document &other) = default;
|
|
|
|
Document &operator=(const Document &other) = delete;
|
|
|
|
Document(Document &&other) = default;
|
|
|
|
Document &operator=(Document &&other) = delete;
|
|
|
|
|
2019-12-28 06:48:35 +01:00
|
|
|
list<Item> new_items;
|
2019-12-25 02:08:53 +01:00
|
|
|
|
|
|
|
void parse();
|
2019-12-20 01:14:23 +01:00
|
|
|
|
|
|
|
private:
|
2019-12-25 06:26:20 +01:00
|
|
|
Config &_cfg;
|
2019-12-28 09:01:17 +01:00
|
|
|
ProfileData &_profiledata;
|
2019-12-20 01:14:23 +01:00
|
|
|
string _raw_doc;
|
2019-12-29 00:05:13 +01:00
|
|
|
list<string> _watchwords;
|
2019-12-25 02:08:53 +01:00
|
|
|
|
2019-12-29 00:41:14 +01:00
|
|
|
void download();
|
|
|
|
/*!
|
|
|
|
* @brief Download document.
|
|
|
|
*
|
|
|
|
* @param uri The URI to download.
|
|
|
|
* @param temp_redirect `true` if this is an temporary redirect.
|
|
|
|
*
|
|
|
|
* The argument `temp_redirect` is there for cases where the original URI
|
|
|
|
* is redirected temporarily, and the new URI is redirected permanently.
|
|
|
|
*
|
|
|
|
* @since 0.10.0
|
|
|
|
*/
|
2020-11-21 22:30:24 +01:00
|
|
|
void download(const string &uri, bool temp_redirect = false);
|
2019-12-25 02:08:53 +01:00
|
|
|
void parse_rss(const pt::ptree &tree);
|
2020-11-21 22:30:24 +01:00
|
|
|
[[nodiscard]] string remove_html(string html) const;
|
|
|
|
[[nodiscard]] static string
|
|
|
|
extract_location(const curl_wrapper::answer &answer);
|
2019-12-28 09:48:42 +01:00
|
|
|
string add_hashtags(const string &text);
|
2019-12-29 00:05:13 +01:00
|
|
|
void parse_watchwords();
|
2019-12-20 01:14:23 +01:00
|
|
|
};
|
|
|
|
} // namespace mastorss
|
|
|
|
|
2020-11-21 22:30:24 +01:00
|
|
|
#endif // MASTORSS_DOCUMENT_HPP
|