Added pubDate for each item.

This commit is contained in:
tastytea 2019-04-17 03:04:27 +02:00
parent a9b227f69b
commit d687dc127e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2)
project(gitea2rss
VERSION 0.0.0
VERSION 0.1.0
LANGUAGES CXX
)

View File

@ -21,6 +21,8 @@
#include <cstdint>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
@ -75,7 +77,7 @@ const string get_http(const string &url)
return answer;
}
// RFC 822 compliant time string.
// Convert time_point to RFC 822 compliant time string.
const string strtime(const system_clock::time_point &timepoint)
{
constexpr uint16_t bufsize = 1024;
@ -87,6 +89,15 @@ const string strtime(const system_clock::time_point &timepoint)
return static_cast<const string>(buffer);
}
// Convert ISO 8601 time string to RFC 822 time string.
const string strtime(const string &time)
{
std::tm tm = {};
std::stringstream ss(time);
ss >> std::get_time(&tm, "%Y-%m-%dT%T%z");
return strtime(std::chrono::system_clock::from_time_t(std::mktime(&tm)));
}
int main(int argc, char *argv[])
{
if (argc < 2)
@ -131,8 +142,11 @@ int main(int argc, char *argv[])
<< release["id"].asString() << "</link>\n"
" <guid isPermaLink=\"false\">"
<< domain << " release " << release["id"].asString() << "</guid>\n"
" <description>" << type << "\n\n"
<< release["body"].asString() << "</description>\n";
" <pubDate>"
<< strtime(release["published_at"].asString()) << "</pubDate>"
" <description><![CDATA[<p><strong>" << type << "</strong></p>"
<< "<pre>" << release["body"].asString()
<< "</pre>]]</description>\n";
// for (const Json::Value &file : release["assets"])
// {