A couple of months ago, my friend Sven Guckes passed away.
When we met in person, once or twice a year, it was mostly him teaching me new stuff. That's what he always did, with everyone: Showed people new tips and tricks for the command line, helped them out whenever he could without asking anything in return. In February 2021, he asked in Twitter for a way to convert his text-only conference "diary" (a list of events at a conference) to an RSS feed. I whipped up a quick proof of concept. It was not perfect by any means, but he liked it.
He had a format in his text files like this:
* 2021-02-15 08:10:00
Working for Twitter now?
Sven on Twitter asked to whip up a script to turn diaries into RSS fee
+ds.
* 2021-02-15 08:20:00
That was easy!
All done!
This was easier than expected!
And this is what i came up with.
#!/usr/bin/env perl
use strict;
use warnings;
use HTTP::Date;
use Time::Piece;
use Carp;
my $gmtoffset = 1; # Hours
print '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
+xmlns:atom="http://www.w3.org/2005/Atom">', "\n";
print '<channel>', "\n";
my ($date, $title);
my @content;
while((my $line = <>)) {
chomp $line;
if($line =~ /^\*\ (\d\d\d\d\-\d\d\-\d\d\ \d\d\:\d\d\:\d\d)/) {
my $temp = $1;
if(defined($date)) {
printItem();
}
$date = $temp;;
$title = <>;
@content = ();
chomp $title;
next;
}
next unless defined($date);
push @content, $line;
}
if(defined($date)) {
printItem();
}
print '</channel>', "\n";
print '</rss>', "\n";
exit 0;
sub printItem {
print '<item>', "\n";
print '<title>', $title, '</title>', "\n";
print '<pubDate>', toWebdate($date), '</pubDate>', "\n";
print '<description>', join('<br/>', @content), '</description>',
+"\n";
print '</item>', "\n";
return;
}
sub toWebdate {
my ($localdate) = @_;
my $webdate;
my $unixtime = Time::Piece->strptime($localdate, "%Y-%m-%d %H:%M:%
+S")->epoch();
$unixtime -= $gmtoffset * 3600;
$webdate = time2str($unixtime);
return $webdate;
}
Then you run it with perl diary2rss.pl < testdiary.txt and get:
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:a
+tom="http://www.w3.org/2005/Atom">
<channel>
<item>
<title>Working for Twitter now?</title>
<pubDate>Mon, 15 Feb 2021 07:10:00 GMT</pubDate>
<description><br/>Sven on Twitter asked to whip up a script to turn di
+aries into RSS feeds.<br/></description>
</item>
<item>
<title>That was easy!</title>
<pubDate>Mon, 15 Feb 2021 07:20:00 GMT</pubDate>
<description><br/>All done!<br/><br/>This was easier than expected!</d
+escription>
</item>
</channel>
</rss>
We were planning to get together this year, maybe look into writing a proper tool for him to use. But sadly, this will not happen.
Thank you, Sven, for teaching me so much. I just wish i could have returned the favours.
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'