Rosetta Code:Village Pump/Lang-tag bot/Source: Difference between revisions

Implemented kill switch.
(Created page with '<lang perl>use warnings; use strict; use feature 'say'; use List::Util '&minstr'; use HTML::Entities '&decode_entities'; use MediaWiki::API; use constant DELAY_BETWEEN_EDITS => …')
 
(Implemented kill switch.)
Line 6:
use MediaWiki::API;
 
use constant DELAY_BETWEEN_EDITS => 1510*60; # In seconds.
 
my $username = 'UnderBot';
my $password = 'secret';
 
my $kill_switch_page = 'User talk:UnderBot';
my $kill_switch_trigger = qr/stopediting/;
 
my $tasks_list_path = '/home/hippo/Temporary/tasks';
Line 193 ⟶ 199:
 
my $mw = new MediaWiki::API({api_url => 'http://rosettacode.org/mw/api.php'});
$mw->login({lgname => 'somebody'$username, lgpassword => 'secret'$password})
or die q(Couldn't log in.);
 
Line 199 ⟶ 205:
{my $pagetitle = shift @titles;
say "TITLE: $pagetitle";
 
sleep DELAY_BETWEEN_EDITS;
# Check the kill switch.
my $p = $mw->get_page({title => $pagetitle}) || die;
my $p = $mw->get_page({title => $kill_switch_page}) || die;
$p->{'*'} =~ $kill_switch_trigger and die "Killed.\n";
 
my $p = $mw->get_page({title => $pagetitle}) || die;
my $timestamp = $p->{timestamp}; # To prevent edit conflicts.
my $text = $p->{'*'};
Line 301 ⟶ 311:
# Probably an edit conflict.
{say "Couldn't commit; I'll try again later.";
push @titles, $pagetitle;}}</lang>
 
sleep DELAY_BETWEEN_EDITS;}</lang>
845

edits