Difference between revisions of "User:Eidobot"
Jump to navigation
Jump to search
(Gave source code.) |
m (Text replace - "nethack.wikia.com" to "nethackwiki.com") |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 30: | Line 30: | ||
use WWW::Mechanize; | use WWW::Mechanize; | ||
− | # Eidobot 1. | + | # Eidobot 1.1 |
− | # Automates upload of new articles to | + | # Automates upload of new articles to NetHackWiki. |
# It uploads every file it can in the directory called new_articles under the | # It uploads every file it can in the directory called new_articles under the | ||
Line 47: | Line 47: | ||
our $pass = 'pass'; | our $pass = 'pass'; | ||
our $summary = 'Automated article upload'; | our $summary = 'Automated article upload'; | ||
+ | our $minor = 1; # mark every edit as minor | ||
our $sleep = 30; # seconds to sleep after each new article | our $sleep = 30; # seconds to sleep after each new article | ||
Line 55: | Line 56: | ||
# LOGIN | # LOGIN | ||
− | $mech->get("http:// | + | $mech->get("http://nethackwiki.com/index.php?title=Special:Userlogin"); |
$mech->submit_form | $mech->submit_form | ||
( | ( | ||
form_name => 'userlogin', | form_name => 'userlogin', | ||
− | fields => { | + | fields => |
+ | { | ||
wpName => $name, | wpName => $name, | ||
wpPassword => $pass, | wpPassword => $pass, | ||
Line 74: | Line 76: | ||
$article =~ s/ /_/g; | $article =~ s/ /_/g; | ||
− | if ($mech->get("http:// | + | if ($mech->get("http://nethackwiki.com/index.php?title=$article&action=edit")->content() |
!~ /To create the page, start typing in the box below/) | !~ /To create the page, start typing in the box below/) | ||
{ | { | ||
Line 81: | Line 83: | ||
} | } | ||
− | $contents =~ s | + | $contents =~ s{ ^ (.*) $ \n }{}xm |
and local $summary = $1 | and local $summary = $1 | ||
− | if !defined($summary) || $summary eq ''; | + | if !defined($summary) || $summary eq <nowiki>''</nowiki>; |
print "Submitting new article \"$article\" (length " . length($contents) . ").\n"; | print "Submitting new article \"$article\" (length " . length($contents) . ").\n"; | ||
Line 90: | Line 92: | ||
( | ( | ||
form_name => 'editform', | form_name => 'editform', | ||
− | fields => { | + | fields => |
− | wpTextbox1 => $contents, | + | { |
− | wpSummary | + | wpTextbox1 => $contents, |
+ | wpSummary => $summary, | ||
+ | wpMinoredit => $minor, | ||
}, | }, | ||
); | ); |
Latest revision as of 19:38, 11 November 2010
Eidobot is written by Eidolos. Please talk to him if you have any issues.
Source code
#!/usr/bin/perl # Copyright (c) 2006 Shawn M Moore # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in al # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. use strict; use warnings; use WWW::Mechanize; # Eidobot 1.1 # Automates upload of new articles to NetHackWiki. # It uploads every file it can in the directory called new_articles under the # current working directory. # The filename corresponds exactly to the new article name. # Change the name and pass variables to your bot's name/pass. # If the summary variable is empty or undefined, it will instead use the first # line of each article for its summary, removing it from the article body. # TODO: More configuration options, error-checking. our $name = 'name'; our $pass = 'pass'; our $summary = 'Automated article upload'; our $minor = 1; # mark every edit as minor our $sleep = 30; # seconds to sleep after each new article opendir(NEW_ARTICLES, 'new_articles') or die "Unable to open new_articles directory: $!"; our $mech = WWW::Mechanize->new(agent => "Eidobot 1.0"); # LOGIN $mech->get("http://nethackwiki.com/index.php?title=Special:Userlogin"); $mech->submit_form ( form_name => 'userlogin', fields => { wpName => $name, wpPassword => $pass, }, ); # SUBMIT LOOP foreach my $article (sort readdir(NEW_ARTICLES)) { next if -d $article; my $contents = do {local (@ARGV, $/) = "new_articles/$article"; <>}; $article =~ s/ /_/g; if ($mech->get("http://nethackwiki.com/index.php?title=$article&action=edit")->content() !~ /To create the page, start typing in the box below/) { warn "Existing article at $article. Skipping!"; next; } $contents =~ s{ ^ (.*) $ \n }{}xm and local $summary = $1 if !defined($summary) || $summary eq ''; print "Submitting new article \"$article\" (length " . length($contents) . ").\n"; $mech->submit_form ( form_name => 'editform', fields => { wpTextbox1 => $contents, wpSummary => $summary, wpMinoredit => $minor, }, ); sleep($sleep) if defined($sleep) && $sleep > 0; }