Approved 2015-01-28, completed 2015-01-30 Wikipedia:Bots/Requests for approval/AnomieBOT II 3 |
package tasks::PageCreator3;
=pod
=begin metadata
Bot: AnomieBOT II
Task: PageCreator3
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT II 3
Status: Completed 2015-01-30
Created: 2015-01-18
Create redirects from [[Regional Indicator Symbol]] pairs to the corresponding flag article.
=end metadata
=cut
use utf8;
use strict;
use AnomieBOT::Task;
use Data::Dumper;
use vars qw/@ISA/;
@ISA=qw/AnomieBOT::Task/;
my $req="[[Wikipedia:Bots/Requests for approval/AnomieBOT II 3|request]]";
my %redirects = (
'๐ฆ๐ฉ' => 'Flag of Andorra',
'๐ฆ๐ช' => 'Flag of the United Arab Emirates',
'๐ฆ๐ซ' => 'Flag of Afghanistan',
'๐ฆ๐ฌ' => 'Flag of Antigua and Barbuda',
'๐ฆ๐ฎ' => 'Flag of Anguilla',
'๐ฆ๐ฑ' => 'Flag of Albania',
'๐ฆ๐ฒ' => 'Flag of Armenia',
'๐ฆ๐ด' => 'Flag of Angola',
'๐ฆ๐ถ' => 'Flags of Antarctica',
'๐ฆ๐ท' => 'Flag of Argentina',
'๐ฆ๐ธ' => 'Flag of American Samoa',
'๐ฆ๐น' => 'Flag of Austria',
'๐ฆ๐บ' => 'Flag of Australia',
'๐ฆ๐ผ' => 'Flag of Aruba',
'๐ฆ๐ฝ' => 'Flag of ร
land',
'๐ฆ๐ฟ' => 'Flag of Azerbaijan',
'๐ง๐ฆ' => 'Flag of Bosnia and Herzegovina',
'๐ง๐ง' => 'Flag of Barbados',
'๐ง๐ฉ' => 'Flag of Bangladesh',
'๐ง๐ช' => 'Flag of Belgium',
'๐ง๐ซ' => 'Flag of Burkina Faso',
'๐ง๐ฌ' => 'Flag of Bulgaria',
'๐ง๐ญ' => 'Flag of Bahrain',
'๐ง๐ฎ' => 'Flag of Burundi',
'๐ง๐ฏ' => 'Flag of Benin',
'๐ง๐ฑ' => 'Flag and coat of arms of Saint Barthรฉlemy',
'๐ง๐ฒ' => 'Flag of Bermuda',
'๐ง๐ณ' => 'Flag of Brunei',
'๐ง๐ด' => 'Flag of Bolivia',
'๐ง๐ถ' => 'Flag of the Netherlands',
'๐ง๐ธ' => 'Flag of the Bahamas',
'๐ง๐น' => 'Flag of Bhutan',
'๐ง๐ป' => 'Flag of Norway',
'๐ง๐ผ' => 'Flag of Botswana',
'๐ง๐พ' => 'Flag of Belarus',
'๐ง๐ฟ' => 'Flag of Belize',
'๐จ๐ฆ' => 'Flag of Canada',
'๐จ๐จ' => 'Flag of the Cocos (Keeling) Islands',
'๐จ๐ฉ' => 'Flag of the Democratic Republic of the Congo',
'๐จ๐ซ' => 'Flag of the Central African Republic',
'๐จ๐ฌ' => 'Flag of the Republic of the Congo',
'๐จ๐ญ' => 'Flag of Switzerland',
'๐จ๐ฎ' => 'Flag of Ivory Coast',
'๐จ๐ฐ' => 'Flag of the Cook Islands',
'๐จ๐ฑ' => 'Flag of Chile',
'๐จ๐ฒ' => 'Flag of Cameroon',
'๐จ๐ณ' => 'Flag of China',
'๐จ๐ด' => 'Flag of Colombia',
'๐จ๐ท' => 'Flag of Costa Rica',
'๐จ๐บ' => 'Flag of Cuba',
'๐จ๐ป' => 'Flag of Cape Verde',
'๐จ๐ผ' => 'Flag of Curaรงao',
'๐จ๐ฝ' => 'Flag of Christmas Island',
'๐จ๐พ' => 'Flag of Cyprus',
'๐จ๐ฟ' => 'Flag of the Czech Republic',
'๐ฉ๐ช' => 'Flag of Germany',
'๐ฉ๐ฏ' => 'Flag of Djibouti',
'๐ฉ๐ฐ' => 'Flag of Denmark',
'๐ฉ๐ฒ' => 'Flag of Dominica',
'๐ฉ๐ด' => 'Flag of the Dominican Republic',
'๐ฉ๐ฟ' => 'Flag of Algeria',
'๐ช๐จ' => 'Flag of Ecuador',
'๐ช๐ช' => 'Flag of Estonia',
'๐ช๐ฌ' => 'Flag of Egypt',
'๐ช๐ญ' => 'Flag of Western Sahara',
'๐ช๐ท' => 'Flag of Eritrea',
'๐ช๐ธ' => 'Flag of Spain',
'๐ช๐น' => 'Flag of Ethiopia',
'๐ซ๐ฎ' => 'Flag of Finland',
'๐ซ๐ฏ' => 'Flag of Fiji',
'๐ซ๐ฐ' => 'Flag of the Falkland Islands',
'๐ซ๐ฒ' => 'Flag of the Federated States of Micronesia',
'๐ซ๐ด' => 'Flag of the Faroe Islands',
'๐ซ๐ท' => 'Flag of France',
'๐ฌ๐ฆ' => 'Flag of Gabon',
'๐ฌ๐ง' => 'Flag of the United Kingdom',
'๐ฌ๐ฉ' => 'Flag of Grenada',
'๐ฌ๐ช' => 'Flag of Georgia (country)',
'๐ฌ๐ซ' => 'Flag of French Guiana',
'๐ฌ๐ฌ' => 'Flag of Guernsey',
'๐ฌ๐ญ' => 'Flag of Ghana',
'๐ฌ๐ฎ' => 'Flag of Gibraltar',
'๐ฌ๐ฑ' => 'Flag of Greenland',
'๐ฌ๐ฒ' => 'Flag of the Gambia',
'๐ฌ๐ณ' => 'Flag of Guinea',
'๐ฌ๐ต' => 'Flag of Guadeloupe',
'๐ฌ๐ถ' => 'Flag of Equatorial Guinea',
'๐ฌ๐ท' => 'Flag of Greece',
'๐ฌ๐ธ' => 'Flag of South Georgia and the South Sandwich Islands',
'๐ฌ๐น' => 'Flag of Guatemala',
'๐ฌ๐บ' => 'Flag of Guam',
'๐ฌ๐ผ' => 'Flag of Guinea-Bissau',
'๐ฌ๐พ' => 'Flag of Guyana',
'๐ญ๐ฐ' => 'Flag of Hong Kong',
'๐ญ๐ฒ' => 'Flag of Australia',
'๐ญ๐ณ' => 'Flag of Honduras',
'๐ญ๐ท' => 'Flag of Croatia',
'๐ญ๐น' => 'Flag of Haiti',
'๐ญ๐บ' => 'Flag of Hungary',
'๐ฎ๐ฉ' => 'Flag of Indonesia',
'๐ฎ๐ช' => 'Flag of Ireland',
'๐ฎ๐ฑ' => 'Flag of Israel',
'๐ฎ๐ฒ' => 'Flag of the Isle of Man',
'๐ฎ๐ณ' => 'Flag of India',
'๐ฎ๐ด' => 'Flag of the British Indian Ocean Territory',
'๐ฎ๐ถ' => 'Flag of Iraq',
'๐ฎ๐ท' => 'Flag of Iran',
'๐ฎ๐ธ' => 'Flag of Iceland',
'๐ฎ๐น' => 'Flag of Italy',
'๐ฏ๐ช' => 'Flag of Jersey',
'๐ฏ๐ฒ' => 'Flag of Jamaica',
'๐ฏ๐ด' => 'Flag of Jordan',
'๐ฏ๐ต' => 'Flag of Japan',
'๐ฐ๐ช' => 'Flag of Kenya',
'๐ฐ๐ฌ' => 'Flag of Kyrgyzstan',
'๐ฐ๐ญ' => 'Flag of Cambodia',
'๐ฐ๐ฎ' => 'Flag of Kiribati',
'๐ฐ๐ฒ' => 'Flag of Comoros',
'๐ฐ๐ณ' => 'Flag of Saint Kitts and Nevis',
'๐ฐ๐ต' => 'Flag of North Korea',
'๐ฐ๐ท' => 'Flag of South Korea',
'๐ฐ๐ผ' => 'Flag of Kuwait',
'๐ฐ๐พ' => 'Flag of the Cayman Islands',
'๐ฐ๐ฟ' => 'Flag of Kazakhstan',
'๐ฑ๐ฆ' => 'Flag of Laos',
'๐ฑ๐ง' => 'Flag of Lebanon',
'๐ฑ๐จ' => 'Flag of Saint Lucia',
'๐ฑ๐ฎ' => 'Flag of Liechtenstein',
'๐ฑ๐ฐ' => 'Flag of Sri Lanka',
'๐ฑ๐ท' => 'Flag of Liberia',
'๐ฑ๐ธ' => 'Flag of Lesotho',
'๐ฑ๐น' => 'Flag of Lithuania',
'๐ฑ๐บ' => 'Flag of Luxembourg',
'๐ฑ๐ป' => 'Flag of Latvia',
'๐ฑ๐พ' => 'Flag of Libya',
'๐ฒ๐ฆ' => 'Flag of Morocco',
'๐ฒ๐จ' => 'Flag of Monaco',
'๐ฒ๐ฉ' => 'Flag of Moldova',
'๐ฒ๐ช' => 'Flag of Montenegro',
'๐ฒ๐ซ' => 'Flag of the Collectivity of Saint Martin',
'๐ฒ๐ฌ' => 'Flag of Madagascar',
'๐ฒ๐ญ' => 'Flag of the Marshall Islands',
'๐ฒ๐ฐ' => 'Flag of the Republic of Macedonia',
'๐ฒ๐ฑ' => 'Flag of Mali',
'๐ฒ๐ฒ' => 'Flag of Burma',
'๐ฒ๐ณ' => 'Flag of Mongolia',
'๐ฒ๐ด' => 'Flag of Macau',
'๐ฒ๐ต' => 'Flag of the Northern Mariana Islands',
'๐ฒ๐ถ' => 'Flag of Martinique',
'๐ฒ๐ท' => 'Flag of Mauritania',
'๐ฒ๐ธ' => 'Flag of Montserrat',
'๐ฒ๐น' => 'Flag of Malta',
'๐ฒ๐บ' => 'Flag of Mauritius',
'๐ฒ๐ป' => 'Flag of the Maldives',
'๐ฒ๐ผ' => 'Flag of Malawi',
'๐ฒ๐ฝ' => 'Flag of Mexico',
'๐ฒ๐พ' => 'Flag of Malaysia',
'๐ฒ๐ฟ' => 'Flag of Mozambique',
'๐ณ๐ฆ' => 'Flag of Namibia',
'๐ณ๐จ' => 'Flag of New Caledonia',
'๐ณ๐ช' => 'Flag of Niger',
'๐ณ๐ซ' => 'Flag of Norfolk Island',
'๐ณ๐ฌ' => 'Flag of Nigeria',
'๐ณ๐ฎ' => 'Flag of Nicaragua',
'๐ณ๐ฑ' => 'Flag of the Netherlands',
'๐ณ๐ด' => 'Flag of Norway',
'๐ณ๐ต' => 'Flag of Nepal',
'๐ณ๐ท' => 'Flag of Nauru',
'๐ณ๐บ' => 'Flag of Niue',
'๐ณ๐ฟ' => 'Flag of New Zealand',
'๐ด๐ฒ' => 'Flag of Oman',
'๐ต๐ฆ' => 'Flag of Panama',
'๐ต๐ช' => 'Flag of Peru',
'๐ต๐ซ' => 'Flag of French Polynesia',
'๐ต๐ฌ' => 'Flag of Papua New Guinea',
'๐ต๐ญ' => 'Flag of the Philippines',
'๐ต๐ฐ' => 'Flag of Pakistan',
'๐ต๐ฑ' => 'Flag of Poland',
'๐ต๐ฒ' => 'Flag of Saint Pierre and Miquelon',
'๐ต๐ณ' => 'Flag and coat of arms of the Pitcairn Islands',
'๐ต๐ท' => 'Flag of Puerto Rico',
'๐ต๐ธ' => 'Palestinian flag',
'๐ต๐น' => 'Flag of Portugal',
'๐ต๐ผ' => 'Flag of Palau',
'๐ต๐พ' => 'Flag of Paraguay',
'๐ถ๐ฆ' => 'Flag of Qatar',
'๐ท๐ช' => 'Flag of Rรฉunion',
'๐ท๐ด' => 'Flag of Romania',
'๐ท๐ธ' => 'Flag of Serbia',
'๐ท๐บ' => 'Flag of Russia',
'๐ท๐ผ' => 'Flag of Rwanda',
'๐ธ๐ฆ' => 'Flag of Saudi Arabia',
'๐ธ๐ง' => 'Flag of the Solomon Islands',
'๐ธ๐จ' => 'Flag of the Seychelles',
'๐ธ๐ฉ' => 'Flag of Sudan',
'๐ธ๐ช' => 'Flag of Sweden',
'๐ธ๐ฌ' => 'Flag of Singapore',
'๐ธ๐ญ' => 'Flag of Saint Helena, Ascension and Tristan da Cunha',
'๐ธ๐ฎ' => 'Flag of Slovenia',
'๐ธ๐ฏ' => 'Flag of Norway',
'๐ธ๐ฐ' => 'Flag of Slovakia',
'๐ธ๐ฑ' => 'Flag of Sierra Leone',
'๐ธ๐ฒ' => 'Flag of San Marino',
'๐ธ๐ณ' => 'Flag of Senegal',
'๐ธ๐ด' => 'Flag of Somalia',
'๐ธ๐ท' => 'Flag of Suriname',
'๐ธ๐ธ' => 'Flag of South Sudan',
'๐ธ๐น' => 'Flag of Sรฃo Tomรฉ and Prรญncipe',
'๐ธ๐ป' => 'Flag of El Salvador',
'๐ธ๐ฝ' => 'Flag of Sint Maarten',
'๐ธ๐พ' => 'Flag of Syria',
'๐ธ๐ฟ' => 'Flag of Swaziland',
'๐น๐จ' => 'Flag of the Turks and Caicos Islands',
'๐น๐ฉ' => 'Flag of Chad',
'๐น๐ซ' => 'Flags of Antarctica#Adรฉlie Land/French Southern and Antarctic Territories',
'๐น๐ฌ' => 'Flag of Togo',
'๐น๐ญ' => 'Flag of Thailand',
'๐น๐ฏ' => 'Flag of Tajikistan',
'๐น๐ฐ' => 'Flag of Tokelau',
'๐น๐ฑ' => 'Flag of East Timor',
'๐น๐ฒ' => 'Flag of Turkmenistan',
'๐น๐ณ' => 'Flag of Tunisia',
'๐น๐ด' => 'Flag of Tonga',
'๐น๐ท' => 'Flag of Turkey',
'๐น๐น' => 'Flag of Trinidad and Tobago',
'๐น๐ป' => 'Flag of Tuvalu',
'๐น๐ผ' => 'Flag of the Republic of China',
'๐น๐ฟ' => 'Flag of Tanzania',
'๐บ๐ฆ' => 'Flag of Ukraine',
'๐บ๐ฌ' => 'Flag of Uganda',
'๐บ๐ฒ' => 'Flag of the United States',
'๐บ๐ธ' => 'Flag of the United States',
'๐บ๐พ' => 'Flag of Uruguay',
'๐บ๐ฟ' => 'Flag of Uzbekistan',
'๐ป๐ฆ' => 'Flag of Vatican City',
'๐ป๐จ' => 'Flag of Saint Vincent and the Grenadines',
'๐ป๐ช' => 'Flag of Venezuela',
'๐ป๐ฌ' => 'Flag of the British Virgin Islands',
'๐ป๐ฎ' => 'Flag of the United States Virgin Islands',
'๐ป๐ณ' => 'Flag of Vietnam',
'๐ป๐บ' => 'Flag of Vanuatu',
'๐ผ๐ซ' => 'Flag of Wallis and Futuna',
'๐ผ๐ธ' => 'Flag of Samoa',
'๐พ๐ช' => 'Flag of Yemen',
'๐พ๐น' => 'Flag and coat of arms of Mayotte',
'๐ฟ๐ฆ' => 'Flag of South Africa',
'๐ฟ๐ฒ' => 'Flag of Zambia',
'๐ฟ๐ผ' => 'Flag of Zimbabwe',
);
sub new {
my $class=shift;
my $self=$class->SUPER::new();
bless $self, $class;
return $self;
}
=pod
=for info
Approved 2015-01-28, completed 2015-01-30<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT II 3]]
=cut
sub approved {
return -200;
}
sub run {
my ($self, $api)=@_;
$api->task('PageCreator3', 0, 10, qw/d::Redirects/);
# Spend a max of 5 minutes on this task before restarting
my $endtime=time()+300;
# First, resolve redirects in the targets list
my %resolved = $api->resolve_redirects( values %redirects );
if ( exists( $resolved{''} ) ) {
$api->warn("Could not resolve redirects: ".$resolved{''}{'error'}."\n");
return 60;
}
my ($code, $target);
while ( ($code, $target) = each( %redirects ) ) {
next if exists($api->store->{$code});
$target = $api->apply_redirect_map( $target, \%resolved );
my $res = $api->query( titles => $target );
if ( $res->{'code'} ne 'success' ) {
$api->warn("Failed to test existence of $target: ".$res->{'error'}."\n");
return 60;
}
if ( exists( $res->{'query'}{'pages'}{'-1'} ) ) {
$api->warn("Target page $target does not exist\n");
next;
}
my $tok=$api->edittoken($code, EditRedir => 1);
if($tok->{'code'} eq 'shutoff'){
$api->warn("Task disabled: ".$tok->{'content'}."\n");
return 300;
}
if($tok->{'code'} ne 'success'){
$api->warn("Failed to get edit token for $code/".$tok->{'error'}."\n");
next;
}
if(!exists($tok->{'missing'})){
$api->log("$code already exists, skipping");
$api->store->{$code}=1;
next;
}
# Create page
my $summary = "Redirecting [[Regional Indicator Symbol]] [[$code]] to [[$target]] per $req";
my $txt = "#REDIRECT [[$target]]";
$api->log("$summary in $code");
my $r=$api->edit($tok, $txt, $summary, 0, 1);
if($r->{'code'} ne 'success'){
$api->warn("Write failed on $code: ".$r->{'error'}."\n");
next;
}
$api->store->{$code}=1;
# If we've been at it long enough, let another task have a go.
return 0 if time()>=$endtime;
}
$api->log("Task may be complete!");
return 600;
}
1;