first version

This commit is contained in:
Alexander 2023-02-17 01:05:20 +00:00
parent 3b9313ab0b
commit 662ce0b6d1
1 changed files with 58 additions and 0 deletions

58
masto2gemlog.pl Executable file
View File

@ -0,0 +1,58 @@
#! /usr/bin/perl
use strict;
my $count=`xmllint --xpath 'count(/rss/channel/item)' alexlehm.rss`;
my %post;
for(my $i=1;$i<=$count;$i++) {
my $date=`xmllint --xpath "string(/rss/channel/item[$i]/pubDate)" alexlehm.rss`;
my $text=`xmllint --xpath "string(/rss/channel/item[$i]/description)" alexlehm.rss`;
my $media=`xmllint --xpath "string(/rss/channel/item[$i]/*[name()='media:content']/\@url)" alexlehm.rss`;
chop $media;
# figure out the date
$date=~/ (\d+) (\S+) (\d+) /;
my $filedate="$3-$2-$1";
print "$date $filedate\n";
# html to gemtext conversion
$text=~s@<p>@@g;
$text=~s@</p>@@g;
$text=~s@<br />@\n@g;
# hashtags are converted to links
# <a href="https://mastodon.social/tags/framagit" class="mention hashtag" rel="tag">#<span>framagit</span></a>
$text=~s@<a href=\"[^\"]+\" class=\"mention hashtag\" rel=\"tag\">#<span>(.*)</span></a>@#$1@g;
$text=~s@&#39;@'@g;
$text=~s@&quot;@"@g;
if($media ne "") {
system("wget -nc $media");
$media =~ s@.*/@@;
$media="=> $media\n";
}
$post{$filedate}.="# $date
$text
$media
";
}
foreach my $d (keys(%post)) {
print "$d\n";
open(FILE, ">$d.gmi");
print FILE $post{$d};
close FILE;
}