-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wpdb_livingdead.pl
executable file
·92 lines (69 loc) · 2.87 KB
/
Wpdb_livingdead.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
# Fluffbot listing people that both is alive and has a year of death
# Copyright (C) User:Fluff 2017
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use lib "/data/project/perfectbot/Fluffbot/mediawikiapi/lib";
use DBI;
use Data::Dumper;
use Encode;
use MediaWiki::API;
require '/data/project/perfectbot/Fluffbot/common.pl';
my $bot = MediaWiki::API->new({ api_url => "https://sv.wikipedia.org/w/api.php" });
open(P, "</data/project/perfectbot/.pwd-Fluffbot") || die("Could not find password");
my $pwd = <P>;
chomp($pwd);
$bot->login({ lgname => "Fluffbot", lgpassword => $pwd });
my $nslist = $bot->api({
action => "query",
meta => "siteinfo",
siprop => "namespaces"
});
my %ns;
foreach my $nsid (keys %{$nslist->{query}->{namespaces}}) {
$ns{$nsid} = $nslist->{query}->{namespaces}->{$nsid}->{'*'};
}
my $dbh = DBI->connect("dbi:mysql:mysql_read_default_file=/data/project/perfectbot/.my.cnf;hostname=svwiki.labsdb;database=svwiki_p", undef, undef, {RaiseError => 1, AutoCommit => 1});
my $sth2 = $dbh->prepare(qq!SELECT cl_to FROM categorylinks WHERE cl_to RLIKE ? AND cl_from = ?!);
my @interesting;
my $sth = $dbh->prepare(qq!SELECT cl_from FROM categorylinks WHERE cl_to = ?!);
$sth->execute('Levande_personer');
while(my $page = $sth->fetchrow_array()) {
$sth2->execute(qq!^Avlidna_[0-9]+\$!, $page);
if($sth2->rows()) {
my $acat = $sth2->fetchrow_array();
$acat =~ /(\d+)/g;
my $ayear = $1;
push @interesting, [$page, $acat, $ayear];
}
}
$sth = $dbh->prepare(qq!SELECT page_namespace, page_title FROM page WHERE page_id = ?!);
my $curcat = "";
my $pagetext = "Detta är en lista över personer som är kategoriserade som både avlidna och levande personer. Listan uppdaterades senast den " . getwikidate() . "\n\n";
foreach(sort {$a->[0] cmp $b->[0] } @interesting) {
$sth->execute($_->[0]);
my ($pagens, $pagetitle) = $sth->fetchrow_array();
$pagetitle =~ s/\_/\ /g;
if($pagens == 0) {
$pagetext .= "* [[:$pagetitle]]";
}
else {
$pagetext .= "* [[:$ns{$pagens}:$pagetitle]]";
}
$pagetext .= " ([[:Kategori:$_->[1]|$_->[2]]])\n";
}
$bot->edit({
action => "edit",
bot => 1,
title => "User:Fluffbot/Personer som \x{e4}r levande d\x{f6}da",
text => Encode::decode("utf-8", $pagetext),
summary => "Uppdaterar listan"
});