Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (82 sloc) 2.01 KB
#~
# compile: obc -src rss_https_xml_15.obs -lib xml.obl,collect.obl -dest rss_https_xml_15.obe
# run: obr rss_https_xml_15.obe "https://www.techmeme.com/feed.xml" <filename>
~#
use Web.HTTP;
use Collection;
use System.IO.File;
class RSS {
function : Main(args : String[]) ~ Nil {
if(args->Size() > 0) {
reader := RSSReader->New(args[0]);
if(reader->IsOk()) {
html := "<html><body>";
GetMetaData(html, reader->GetChannel());
GetPosts(html, reader->GetPosts());
html += "</body></html>";
if(args->Size() = 2) {
WriteHtml(html, args[1]);
}
else {
html->PrintLine();
};
};
};
}
function : WriteHtml(html : String, file : String) ~ Nil {
out := FileWriter->New(file);
leaving {
out->Close();
};
out->WriteString(html);
"Wrote file: {$file}..."->PrintLine();
}
function : GetMetaData(html : String, channel : RSSChannel) ~ Nil {
title := channel->GetTitle();
description := channel->GetDescription();
link := channel->GetLink();
html += "<b><a href='";
html += link;
html += "'>";
html += title;
html += "</a></b></br><p>";
html += description;
html += "</p>";
}
function : GetPosts(html : String, posts : Vector) ~ Nil {
each(i : posts) {
post := posts->Get(i)->As(RSSPost);
title := post->GetTitle();
description := post->GetDescription();
link := post->GetLink();
pub_date := post->GetDate();
if(description <> Nil & (description->Find("href") > -1 | description->Find("HREF") > -1)) {
html += "<p><h3>";
html += pub_date;
html += "</h3>";
html += description;
html += "</p>";
}
else if(description <> Nil) {
html += "<p><h3>";
html += pub_date;
html += "</h3><b><a href='";
html += link;
html += "'>";
html += title;
html += "</a></b></br>";
html += description;
html += "</p>";
}
else {
html += "<p><h3>";
html += pub_date;
html += "</h3><b><a href='";
html += link;
html += "'>";
html += title;
html += "</a></b></br></p>";
};
};
}
}