2019-09-03 17:47:39 +02:00
|
|
|
/* This file is part of remwharead.
|
|
|
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
#include "export/json.hpp"
|
|
|
|
#include "time.hpp"
|
2019-09-03 17:47:39 +02:00
|
|
|
#include <Poco/JSON/Object.h>
|
|
|
|
#include <Poco/JSON/Stringifier.h>
|
2019-09-30 13:20:36 +02:00
|
|
|
|
2019-09-03 17:47:39 +02:00
|
|
|
|
|
|
|
namespace remwharead
|
|
|
|
{
|
2019-09-30 13:20:36 +02:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2019-09-03 17:47:39 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
void Export::JSON::print() const
|
|
|
|
{
|
|
|
|
try
|
2019-09-03 17:47:39 +02:00
|
|
|
{
|
2019-09-30 13:20:36 +02:00
|
|
|
Poco::JSON::Array root = Poco::JSON::Array();
|
|
|
|
|
|
|
|
for (const Database::entry &entry : _entries)
|
2019-09-03 17:47:39 +02:00
|
|
|
{
|
2019-09-30 13:20:36 +02:00
|
|
|
Poco::JSON::Object json_entry = Poco::JSON::Object();
|
2019-09-03 17:47:39 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
json_entry.set("uri", entry.uri);
|
|
|
|
json_entry.set("archive_uri", entry.archive_uri);
|
|
|
|
json_entry.set("datetime", timepoint_to_string(entry.datetime));
|
|
|
|
Poco::JSON::Array tags = Poco::JSON::Array();
|
|
|
|
for (const string &tag : entry.tags)
|
2019-09-03 17:47:39 +02:00
|
|
|
{
|
2019-09-30 13:20:36 +02:00
|
|
|
tags.add(tag);
|
2019-09-03 17:47:39 +02:00
|
|
|
}
|
2019-09-30 13:20:36 +02:00
|
|
|
json_entry.set("tags", tags);
|
|
|
|
json_entry.set("title", entry.title);
|
|
|
|
json_entry.set("description", entry.description);
|
|
|
|
json_entry.set("fulltext", entry.fulltext);
|
2019-09-03 17:47:39 +02:00
|
|
|
|
2019-09-30 13:20:36 +02:00
|
|
|
root.add(json_entry);
|
2019-09-03 17:47:39 +02:00
|
|
|
}
|
2019-09-30 13:20:36 +02:00
|
|
|
|
|
|
|
root.stringify(_out);
|
|
|
|
_out << endl;
|
|
|
|
}
|
|
|
|
catch (std::exception &e)
|
|
|
|
{
|
|
|
|
cerr << "Error in " << __func__ << ": " << e.what() << endl;
|
2019-09-03 17:47:39 +02:00
|
|
|
}
|
2019-09-30 13:20:36 +02:00
|
|
|
}
|
2019-09-25 03:58:29 +02:00
|
|
|
} // namespace remwharead
|