#!/usr/bin/perl
#AutoBulletin.pl Version 0.1
#To be used with MyspaceAutoBulletin.php
#Wordpress plugin by Possum
#http://possum.kicks-ass.org/
#This script requires perl (of course) and the
#CPAN module WWW::Mechanize.
#All code licensed under the GPL unless otherwise mentioned.
#"Myspace" and related names are copyrighted or something like
#that by whoever owns/has the rights to Myspace.
use strict;
use warnings;
use lib qw(/home/yubimusubi/lib/perl/5.8.4
/home/yubimusubi/share/perl/5.8.4);
#We'll try something different
#use WWW::MySpaceBot;
use WWW::Mechanize;
#use HTML::Form;
my ($postid,$email,$password,$subject);
my $myspace = WWW::Mechanize->new();
#Mimic Firefox
$myspace->agent_alias( 'Linux Mozilla' );
my $tmpfile = $ARGV[0];
my %paragraphs;
#Make this NOT hardcoded!
our $username='Possum';
parse_tmpfile($tmpfile);
#Sign in
myspace_login($email,$password);
#Log
#NOTE: MAKE LOGFILE CONFIGURABLE AND OPTIONAL!
open(OUTPUT,'>/home/yubimusubi/autobul.out');
print OUTPUT "Logged in as " . $username . "\n";
print OUTPUT "The post $subject contains the following:\n";
print OUTPUT "$paragraphs{0}\n$paragraphs{1}";
close(OUTPUT);
my $blogurl="http://possum.kicks-ass.org"; #configurable by
my $blogname="possum.kicks-ass.org"; #$wpdb in php script?
#Code will go here to translate user-configurable
#strings, i.e., %u=$username, %b=blogsitename, etc.
#But that's for version 0.2!
my $post_subject="$username posted new entry: $subject!";
my $post_message="A new blog entry has been posted by $username at $blogname.\n$subject contains the following:\n$paragraphs{0}\nClick here to read the rest of this entry!";
post_bulletin($post_subject,$post_message);
sub myspace_login{
my ($email,$password)=@_;
my $login_uri='http://www.myspace.com/';
$myspace->get($login_uri);
$myspace->submit_form(
#myspace may change these values
form_name => 'theForm',
fields => {
email => $email,
password => $password,
}
);
#print $myspace->content( format => "text" );
#Skip Advert
$myspace->follow_link( text_regex => qr/Skip this Advertisement/i );
}
sub post_bulletin {
my ($subject,$body)=@_;
#See what we can do
#Need some error recovery!
#print $myspace->uri() . "\n";
#print $myspace->content( format => "text" ) . "\n";
my $bulletinlink = $myspace->find_link( text_regex => qr/post bulletin$/i );
#print $bulletinlink;
$myspace->get( $bulletinlink );
#We assume we get there :(
$myspace->submit_form(
form_name => 'bulletinForm',
fields => {
subject => $subject,
body => $body,
}
);
#Click to confirm
$myspace->submit_form(
form_name => 'bulletinForm',
);
#Courtesy of Ciaran
#my $content = $myspace->content;
#my ($actionurl) = $content=~/Bulletin" onclick="document\.bulletinForm\.action='(.*?)';/;
#My code again
#$myspace->form_number(3);
#my $form=$myspace->current_form();
#$form->action($actionurl);
#$myspace->submit();
#$form->click(1,1);
#We _hope_ this will work!
#print $myspace->content( format => "text" ) . "\n";
}
sub parse_tmpfile{
my $file=$_[0];
my $paragraph=0;
if (open(OUTPUT,'>/home/yubimusubi/autobul.out')) {
if (open(MABINPUT,"<$tmpfile")) {
while () {
chomp;
(undef,$postid)=split(/ /,$_) if /^MABPostID:/;
(undef,$email)=split(/ /, $_) if /^MABEmail:/;
(undef,$password)=split(/ /, $_) if /^MABPassword:/;
(undef,$subject)=split(/ /,$_, 2) if /^MABSubject:/;
unless (/^MAB/) {
if (/^\s*$/) {
$paragraph++;
next;
} else {
$paragraphs{$paragraph} .= $_ . "\n";
}
}
}
close(MABINPUT);
#unlink($tmpfile);
close(OUTPUT);
} else {
print OUTPUT "ERROR! Cannot open $tmpfile.";
}
} else {
die "Cannot open logfile\n";
}
}