Last active
August 29, 2015 14:01
-
-
Save yaasita/1a6ecce213edd08df5ba to your computer and use it in GitHub Desktop.
blogger2middleman
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/\</</mg; | |
$content=~s/\>/>/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