first version
This commit is contained in:
parent
3b9313ab0b
commit
662ce0b6d1
|
@ -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@'@'@g;
|
||||
$text=~s@"@"@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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue