From Wikipedia, the free encyclopedia
#!/usr/bin/perl
use Perlwikipedia;
#Create all the Perl Wikipedia Stuff
print "Bot Starting Up\n";
#Create Perl Wikipedia Object
print "\tCreating Perl Wikipedia Object.\n";
$editor=Perlwikipedia->new('Chris G Bot') or die "Error Creating Object : $!\n";
print "\tObject Created.\n";
# Turn debugging on, to see what the bot is doing
print "\tActivating Debuging.\n";
$editor->{debug} = 1;
print "\tDebuging Activated.\n";
print "Bot Started\n";
#Login
login();
#List the articles on Wikipedia:WikiProject Deletion sorting/Australia
my $list1 = listArticles1();
my $list2 = listArticles2();
my $list3 = listArticles3();
my $list4 = listArticles4();
#update the page
updatePage($list1);
print "YAY ALL TASKS ARE DONE!!!!!\n";
sub login {
#This sub contains all the code to log the bot in
# Username and password (change these when the bot has an account).
print "Bot is now logging in.\n";
my $username = 'Chris G Bot';
my $password = 'password';
print "\tBot is now trying to log in as $username with $password as password.\n";
#try to login - if fails exit with error message
$editor->login($username, $password);
print "\tBot is now logged in.\n";
#Sleep for 10 sec
print "\tSleeping for 10 sec\n";
print "Bot now logged in.\n";
}
sub listArticles1 {
print "Listing articles on : Wikipedia:WikiProject Deletion sorting/Australia.\n";
#Get the code from Wikipedia:WikiProject Deletion sorting/Australia
#Delcerations
my $pagename = "Wikipedia:WikiProject Deletion sorting/Australia";
my $revid = 'prev';
my $section_number = 1;
#Get the code
print "\tGetting code from $pagename.\n";
my $code = $editor->get_text($pagename,$revid,$section_number) or die "ERROR getting code from $pagename. Full Deatials : $!";
print "\tDone!\n";
#Clean the code
print "\tCleaning Code.\n";
$code =~ s^==Australia-related Articles for Deletion debates==^^ig;
$code =~ s^{{Wikipedia:Articles for deletion^* {{On AFD|^ig;
$code =~ s^/^^ig;
print $code;
sleep 10;
return $code;
}
sub listArticles2 {
print "Listing articles on : Wikipedia:WikiProject Deletion sorting/Australia.\n";
#Get the code from Wikipedia:WikiProject Deletion sorting/Australia
#Delcerations
my $pagename = "Wikipedia:WikiProject Deletion sorting/Australia";
my $revid = 'prev';
my $section_number = 2;
#Get the code
print "\tGetting code from $pagename.\n";
my $code = $editor->get_text($pagename,$revid,$section_number) or die "ERROR getting code from $pagename. Full Deatials : $!";
print "\tDone!\n";
#Clean the code
print "\tCleaning Code.\n";
$code =~ s^==Australia-related Miscellany for deletion==^^ig;
return $code;
}
sub listArticles3 {
print "Listing articles on : Wikipedia:WikiProject Deletion sorting/Australia.\n";
#Get the code from Wikipedia:WikiProject Deletion sorting/Australia
#Delcerations
my $pagename = "Wikipedia:WikiProject Deletion sorting/Australia";
my $revid = 'prev';
my $section_number = 3;
#Get the code
print "\tGetting code from $pagename.\n";
my $code = $editor->get_text($pagename,$revid,$section_number) or die "ERROR getting code from $pagename. Full Deatials : $!";
print "\tDone!\n";
#Clean the code
print "\tCleaning Code.\n";
$code =~ s^==Australia-related Templates for Discussion==^^ig;
return $code;
}
sub listArticles4 {
print "Listing articles on : Wikipedia:WikiProject Deletion sorting/Australia.\n";
#Get the code from Wikipedia:WikiProject Deletion sorting/Australia
#Delcerations
my $pagename = "Wikipedia:WikiProject Deletion sorting/Australia";
my $revid = 'prev';
my $section_number = 4;
#Get the code
print "\tGetting code from $pagename.\n";
my $code = $editor->get_text($pagename,$revid,$section_number) or die "ERROR getting code from $pagename. Full Deatials : $!";
print "\tDone!\n";
#Clean the code
print "\tCleaning Code.\n";
$code =~ s^==Australia-related Categories for Discussion==^^ig;
return $code;
}
sub updatePage {
my $Add = $list1;
#Get the code from the page
my $pagename = "Wikipedia:Australian Wikipedians' notice board/AfD";
print "\tGettting code from $pagename\n";
my $code = $editor->get_text($pagename) or die "ERRROR Getting text from $pagename Full details : $!.\n";
print "\tDone.\n";
my $code3 = $code;
#Clean the code
print "\tCleaning Code.\n";
my @code = split(/[<][!][-][-] [b][o][t] [s][t][a][r][t] [a][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code);
my @code2 = split(/[<][!][-][-] [b][o][t] [e][n][d] [a][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code[1]);
$code = $code[0] . '<!-- Bot Start Afd (Do not Remove) -->' . $Add . "<!-- Bot End Afd (Do not Remove) -->" . $code2[1];
print "\tCleaning Code.\n";
my @code = split(/[<][!][-][-] [b][o][t] [s][t][a][r][t] [m][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code);
my @code2 = split(/[<][!][-][-] [b][o][t] [e][n][d] [m][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code[1]);
$code = $code[0] . '<!-- Bot Start Mfd (Do not Remove) -->' . $list2 . "<!-- Bot End Mfd (Do not Remove) -->" . $code2[1];
print "\tCleaning Code.\n";
my @code = split(/[<][!][-][-] [b][o][t] [s][t][a][r][t] [t][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code);
my @code2 = split(/[<][!][-][-] [b][o][t] [e][n][d] [t][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code[1]);
$code = $code[0] . '<!-- Bot Start Tfd (Do not Remove) -->' . $list3 . "<!-- Bot End Tfd (Do not Remove) -->" . $code2[1];
print "\tCleaning Code.\n";
my @code = split(/[<][!][-][-] [b][o][t] [s][t][a][r][t] [c][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code);
my @code2 = split(/[<][!][-][-] [b][o][t] [e][n][d] [c][f][d] [(][d][o] [n][o][t] [r][e][m][o][v][e][)] [-][-][>]/i,$code[1]);
$code = $code[0] . '<!-- Bot Start Cfd (Do not Remove) -->' . $list4 . "<!-- Bot End Cfd (Do not Remove) -->" . $code2[1];
#Update page if it needs updating
if ($code ne $code3) {
print "\tUpdating page.\n";
print $code;
sleep 60;
my $edit_summary = "Updating page with content from [[Wikipedia:WikiProject Deletion sorting/Australia]] (BOT EDIT).";
print $code;
$editor->edit($pagename,$code,$edit_summary) or die "ERROR Updating $pagename : $!.\n";
print "\tDone.\n";
}
else {
print "\tPage dosn't need updating will not update.\n";
}
print "Done.\n";
}