Skip to content

Instantly share code, notes, and snippets.

@kan
Created March 19, 2011 09:44
Show Gist options
  • Save kan/877368 to your computer and use it in GitHub Desktop.
Save kan/877368 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Data::Dumper;
use File::Slurp;
use Time::Piece;
use WebService::Tumblr;
use Config::Pit;
my @entry = map {
[ grep {/^(AUTHOR:|BODY:)/} split( '-----\n', $_ ) ]
}
split( '--------\n', read_file( $ARGV[0] ) );
my $c = pit_get( "tumblr.com", require => {
email => 'your email address on tumblr',
password => 'your password on tumblr',
group => 'your tumblog group name',
});
my $tumblr = WebService::Tumblr->new(
email => $c->{email},
password => $c->{password},
);
for my $entry (@entry) {
next unless scalar(@$entry) == 2;
my ( $title, $date, $tags, $body );
if ( $entry->[0] =~ /TITLE: (.+)/ ) {
$title = $1;
}
if ( $entry->[0] =~ /DATE: (.+)/ ) {
$date = Time::Piece->strptime( $1, '%m/%d/%Y %I:%M:%S %p' );
}
$tags = [];
for my $category ( $entry->[0] =~ /CATEGORY: (.+)/g ) {
push @$tags, $category;
}
if ( $entry->[1] =~ m{<div class="section">((.|\r|\n)+)</div>}m ) {
$body = "$1";
$body =~ s/^\s+//mg;
}
my $res = $tumblr->write(
group => $c->{group},
type => 'regular',
format => 'html',
title => $title,
body => $body,
date => $date->strftime('%Y-%m-%d %H:%M:%S'),
tags => join(',', @$tags),
);
warn "post:" . $res->content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment