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) cmake_minimum_required (VERSION 3.2)
project(gitea2rss project(gitea2rss
VERSION 0.0.0 VERSION 0.1.0
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -21,6 +21,8 @@
#include <cstdint> #include <cstdint>
#include <chrono> #include <chrono>
#include <ctime> #include <ctime>
#include <iomanip>
#include <sstream>
#include <curlpp/cURLpp.hpp> #include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp> #include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp> #include <curlpp/Options.hpp>
@ -75,7 +77,7 @@ const string get_http(const string &url)
return answer; 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) const string strtime(const system_clock::time_point &timepoint)
{ {
constexpr uint16_t bufsize = 1024; constexpr uint16_t bufsize = 1024;
@ -87,6 +89,15 @@ const string strtime(const system_clock::time_point &timepoint)
return static_cast<const string>(buffer); 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[]) int main(int argc, char *argv[])
{ {
if (argc < 2) if (argc < 2)
@ -131,8 +142,11 @@ int main(int argc, char *argv[])
<< release["id"].asString() << "</link>\n" << release["id"].asString() << "</link>\n"
" <guid isPermaLink=\"false\">" " <guid isPermaLink=\"false\">"
<< domain << " release " << release["id"].asString() << "</guid>\n" << domain << " release " << release["id"].asString() << "</guid>\n"
" <description>" << type << "\n\n" " <pubDate>"
<< release["body"].asString() << "</description>\n"; << 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"]) // for (const Json::Value &file : release["assets"])
// { // {