diff options
author | Jonas Smedegaard <dr@jones.dk> | 2015-01-07 16:38:38 +0100 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2015-01-07 16:38:38 +0100 |
commit | c33904111ac3b886cd10ff1c3f1dbdcd7c277941 (patch) | |
tree | 27da9a79253e67a66befc52970938a70eb15a040 /mediawiki-fetch | |
parent | 67296ef210458ce48be3942df98624dca66b8c53 (diff) |
Fetch source by use of Mediawiki::API (not wget + custom mediawiki-extract decoding).
Diffstat (limited to 'mediawiki-fetch')
-rwxr-xr-x | mediawiki-fetch | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/mediawiki-fetch b/mediawiki-fetch new file mode 100755 index 0000000..181c84e --- /dev/null +++ b/mediawiki-fetch @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +# fetch content of mediawiki page + +use warnings; +use strict; + +use feature qw(say); + +use Path::Tiny; +use MediaWiki::API; +use DateTime::Format::ISO8601; + +my $base_uri = shift; +my $page_title = shift; +my $outfile = shift; + +my $mw = MediaWiki::API->new( { api_url => $base_uri . 'w/api.php' } ); + +my $page = $mw->get_page( { title => $page_title } ) + || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; + +my $dt = DateTime::Format::ISO8601->parse_datetime( $page->{'timestamp'} ); + +path($outfile)->spew_utf8( $page->{'*'} ); +path($outfile)->touch( $dt->epoch ); + +say STDERR sprintf( 'Succesfully fetched %s (rev. %s)', + $page_title, + $page->{'revid'}); + +1; |