[PerlWikiBot] SF.net SVN: perlwikibot:[88] trunk/no-interwiki
Status: Pre-Alpha
Brought to you by:
rotemliss
|
From: <am...@us...> - 2010-03-26 15:22:09
|
Revision: 88
http://perlwikibot.svn.sourceforge.net/perlwikibot/?rev=88&view=rev
Author: amire80
Date: 2010-03-26 15:22:02 +0000 (Fri, 26 Mar 2010)
Log Message:
-----------
Adding upload_iw.pl.
Modified Paths:
--------------
trunk/no-interwiki/MediaWiki/Toolkit.pm
trunk/no-interwiki/ru.strings.txt
Added Paths:
-----------
trunk/no-interwiki/upload_iw.pl
Modified: trunk/no-interwiki/MediaWiki/Toolkit.pm
===================================================================
--- trunk/no-interwiki/MediaWiki/Toolkit.pm 2010-03-26 14:03:26 UTC (rev 87)
+++ trunk/no-interwiki/MediaWiki/Toolkit.pm 2010-03-26 15:22:02 UTC (rev 88)
@@ -14,7 +14,7 @@
our %EXPORT_TAGS = (
FIELD_SEP => [qw( $FIELD_SEP $FIELD_SEP_RE )],
GET_STRING => [qw( get_strings get_string )],
- FILE_UTIL => [qw( file_error append_to_file )],
+ FILE_UTIL => [qw( file_error append_to_file read_file )],
);
our @EXPORT_OK = map { @{$_} } values %EXPORT_TAGS;
@@ -81,24 +81,35 @@
}
sub file_error {
- my ($operation, $fn, $access_type) = @_;
- my $string = "error $operation $fn, $access_type: $OS_ERROR";
+ my ($operation, $filename, $access_type) = @_;
+ my $string = "error $operation $filename, $access_type: $OS_ERROR";
return $string;
}
sub append_to_file {
- my ($fn, $line) = @_;
+ my ($filename, $line) = @_;
- open my $file, '>>', $fn
- or croak(file_error('opening', $fn, 'appending'));
-
+ open my $file, '>>', $filename
+ or croak(file_error('opening', $filename, 'appending'));
say {$file} ($line // q{}); # /
-
close $file
- or croak(file_error('closing', $fn, 'appeding'));
+ or croak(file_error('closing', $filename, 'appeding'));
return;
}
+sub read_file {
+ my ($filename) = @_;
+
+ local $INPUT_RECORD_SEPARATOR = undef;
+ open my $file, '<', $filename
+ or croak(file_error('opening', $filename, 'reader'));
+ my $text = <$file>;
+ close $file
+ or croak(file_error('closing', $filename, 'reading'));
+
+ return $text;
+}
+
1;
Modified: trunk/no-interwiki/ru.strings.txt
===================================================================
--- trunk/no-interwiki/ru.strings.txt 2010-03-26 14:03:26 UTC (rev 87)
+++ trunk/no-interwiki/ru.strings.txt 2010-03-26 15:22:02 UTC (rev 88)
@@ -30,6 +30,12 @@
Category Категория
article space (статьи)
+# pages
+project prefix Википедия:Проект:Интервики/Виды/Категории
+
+# summaries
+updating list of pages without interwiki обновление списка страниц без интервики
+
# Other
other другое
rlm {{כ}}
Added: trunk/no-interwiki/upload_iw.pl
===================================================================
--- trunk/no-interwiki/upload_iw.pl (rev 0)
+++ trunk/no-interwiki/upload_iw.pl 2010-03-26 15:22:02 UTC (rev 88)
@@ -0,0 +1,114 @@
+#!/usr/bin/perl
+
+use 5.010;
+
+use strict;
+use warnings;
+use open ':encoding(utf8)';
+use utf8;
+
+use English qw(-no_match_vars);
+use Carp qw(croak cluck);
+use Getopt::Long;
+use Data::Dumper;
+use Encode;
+
+use Readonly;
+
+use MediaWiki::API;
+
+use MediaWiki::Toolkit (
+ qw(
+ :GET_STRING
+ :FILE_UTIL)
+);
+
+our $VERSION = '0.01';
+#<<< no perltidy
+my %SVN_PROPS = ( ## no critic (RequireInterpolationOfMetachars)
+ Revision => '$Revision: 0 $',
+ HeadURL => '$HeadURL: https://perlwikibot.svn.sourceforge.net/svnroot/perlwikibot/trunk/no-interwiki/upload_iw.pl $',
+ Date => '$Date: 2010-03-25 17:02:28 +0200 (Thu, 25 Mar 2010) $',
+);
+#>>>
+
+Readonly my $INPUT_EXTENSION => 'wiki.txt';
+Readonly my $INTERVAL_BETWEEN_EDITS => 5;
+
+my %option = (
+ help => 0,
+ usage => 0,
+ version => 0,
+);
+
+my $valid_options = GetOptions(
+ 'langcode=s' => \$option{langcode},
+ 'username=s' => \$option{username},
+ 'password=s' => \$option{password},
+ 'help' => \$option{help},
+ 'usage' => \$option{usage},
+ 'version' => \$option{version},
+);
+
+if (not $valid_options) {
+ croak('Invalid command line options.');
+}
+
+for my $required_option (qw(langcode username password)) {
+ if (not $option{$required_option}) {
+ croak "option $required_option is required";
+ }
+}
+
+get_strings($option{langcode});
+
+my $mw = MediaWiki::API->new();
+$mw->{config}->{api_url} = "http://$option{langcode}.wikipedia.org/w/api.php";
+
+$mw->login(
+ {
+ lgname => $option{username},
+ lgpassword => $option{password},
+ }
+) or croak $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+
+my $page_prefix = get_string('project prefix');
+
+my $dirname = "./out.$option{langcode}/";
+my @filenames = glob $dirname . get_string('Category') . "*.$INPUT_EXTENSION";
+
+say Dumper(\@filenames);
+
+foreach my $filename (@filenames) {
+ my $pagename = Encode::decode('UTF-8', "$filename");
+ for ($pagename) {
+ s/\.$INPUT_EXTENSION\z//xms;
+ s/\A$dirname//xms;
+ }
+ $pagename = "$page_prefix/$pagename";
+
+ my $page = $mw->get_page({ title => $pagename });
+ if ($page->{missing}) {
+ say "page $pagename is missing, trying to create";
+ }
+
+ say "uploading to $pagename";
+
+ $mw->edit(
+ {
+ action => 'edit',
+ title => $pagename,
+ summary => get_string('updating list of pages without interwiki'),
+ basetimestamp => $page->{timestamp},
+ text => read_file($filename),
+ },
+ { skip_encoding => 1, }
+ ) or croak $mw->{error}->{codie} . ': ' . $mw->{error}->{details};
+
+ sleep $INTERVAL_BETWEEN_EDITS;
+}
+
+exit;
+
+__END__
+
Property changes on: trunk/no-interwiki/upload_iw.pl
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|