Skip to content

Instantly share code, notes, and snippets.

@yaasita
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/1a6ecce213edd08df5ba to your computer and use it in GitHub Desktop.
Save yaasita/1a6ecce213edd08df5ba to your computer and use it in GitHub Desktop.
blogger2middleman
#!/usr/bin/perl
use strict;
use warnings;
open (FH,"blog-05-10-2014_2.xml") or die $!;
while (<FH>){
if (/^<entry>/){
open (WR,">/tmp/out/${.}.erb") or die $!;
}
if (/^<entry>/../^<\/entry>/){
print WR;
}
if (/^<\/entry>/){
close WR;
}
}
close FH;
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);
use File::Basename;
my $file = $ARGV[0];
say "sartconvert : $file";
my ($title,@tags,$content);
open (FH,$file) or die $!;
while (<FH>){
if (/^<content/../<\/content>/){
$content.=$_;
}
elsif (/^<title.+?>(.+)<\/title>/){
$title.=$1;
}
elsif (/^<category scheme.+blogger.+term=\'(.+)\'/){
push(@tags,lc $1);
}
}
close FH;
$content=~s/^<content.+?>//;
$content=~s/<\/content>//;
$content=~s/\&lt;/</mg;
$content=~s/\&gt;/>/mg;
if ($content eq ""){
die "content empty";
}
elsif ($title eq ""){
die "title empty";
}
elsif (@tags+0==0){
die "tags empty";
}
my $outfile=basename $file,".erb";
open (WR,">conv/$outfile.erb") or die $!;
say WR "---";
say WR "title: ".$title;
say WR "tags: ".join(", ",@tags);
say WR "---";
say WR "";
say WR $content;
close WR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment