Add your new entry to your blog in blogger with your favorite editor. This program simply using WWW::Mechanize. Default editor is defined with $editor. You can change default editor with --editor argument or $editor variable. You can define $usename and $password for always using. If you dont want to do this you must be start program with --usename and --password arguments.
Also you need
SSLeay module.
Onur noted that the script does not work anymore as of 20100618.
#!/usr/bin/perl
######################################################################
+###
# Addtoblog 0.1
+ #
# Add your new entry to your blog in blogger with your favorite editor
+ #
# Copyright (C) 2007 Onur Aslan <onuraslan@gmail.com>
+ #
#
+ #
# This program is free software: you can redistribute it and/or modify
+ #
# it under the terms of the GNU General Public License as published by
+ #
# the Free Software Foundation, either version 3 of the License, or
+ #
# any later version.
+ #
#
+ #
# This program is distributed in the hope that it will be useful,
+ #
# but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ #
# GNU General Public License for more details.
+ #
#
+ #
# You should have received a copy of the GNU General Public License
+ #
# along with this program. If not, see <http://www.gnu.org/licenses/>
+. #
######################################################################
+###
use strict;
use Getopt::Long;
use WWW::Mechanize;
my $username; # You can define a default value if you want.
my $password; # Otherwise you must start program with --username and
+ --password
my $tmp_file = "/tmp/addtoblog";
my $editor = "vi";
my $template = "# Addtoblog template
# First line must be your entry Title
# Second line must be must be tags, e.g. scooters, vacation, fall\n";
my $mech = WWW::Mechanize->new ();
my $blog_id;
sub initialize
{
GetOptions ("username=s"=>\$username,
"password=s"=>\$password,
"editor=s", =>\$editor);
unless ($username && $password)
{
die "Addtoblog 0.1\n",
"Add your new entry to your blog in blogger with your favori
+te editor\n",
"Default editor: $editor\n",
"You can change editor with --editor argument.\n",
"Usage:\n",
" ./addtoblog --username=USERNAME --password=PASSWORD\n";
}
}
# Login to blogger
sub login
{
print "Connecting to blogger.com...\n";
$mech->get ("https://www.blogger.com/start");
print "Logining to blogger.com...\n";
$mech->submit_form (
form_name => "login",
fields => { Email => $username,
Passwd => $password },
button => "ok"
);
if ($mech->{form} != undef)
{
die "Wrong username or password.\n";
}
$mech->get ("http://www.blogger.com/home");
# Getting blog id
($blog_id) = $mech->{content} =~ /blogID=([\d]+)/;
}
sub new_post
{
# Creating new post template
open FILE, ">$tmp_file";
print FILE $template;
close FILE;
# Opening tmp_file with vi
print "Opening text editor...\n";
system ("$editor $tmp_file");
# Parsing new post
print "Parsing file...\n";
open FILE, $tmp_file;
my @content;
while (<FILE>)
{
if ($_ !~ /^#/)
{
push @content, $_;
}
}
close FILE;
my $title = $content[0];
$title =~ s/\n//g;
shift @content; # Removing title in @content
my $tags = $content[0];
$tags =~ s/\n//g;
shift @content; # Removing tags in @content
my $content = join ("", @content);
# Print information
print "Title: $title\n",
"Tags: $tags\n",
"Content: $content\n",
"Do you want to post this entry to your blog? [Y|n]: ";
my $a = <>;
if ($a eq "\n" || $a =~ /y/i)
{
print "Posting...\n";
$mech->get ("http://www.blogger.com/post-create.g?blogID=$blog_i
+d");
$mech->submit_form (
form_name => "stuffform",
fields => { title => $title,
postBody => $content,
postLabels => $tags },
button => "publish"
);
print "Your entry successfully posted to your blog.\n";
}
}
initialize;
login;
new_post;