blob: 181c84e762490f1a795e49f1eea59e48cca770d1 (
plain)
- #!/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;
|