summaryrefslogtreecommitdiff
path: root/mediawiki-fetch
blob: 181c84e762490f1a795e49f1eea59e48cca770d1 (plain)
  1. #!/usr/bin/perl
  2. # fetch content of mediawiki page
  3. use warnings;
  4. use strict;
  5. use feature qw(say);
  6. use Path::Tiny;
  7. use MediaWiki::API;
  8. use DateTime::Format::ISO8601;
  9. my $base_uri = shift;
  10. my $page_title = shift;
  11. my $outfile = shift;
  12. my $mw = MediaWiki::API->new( { api_url => $base_uri . 'w/api.php' } );
  13. my $page = $mw->get_page( { title => $page_title } )
  14. || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
  15. my $dt = DateTime::Format::ISO8601->parse_datetime( $page->{'timestamp'} );
  16. path($outfile)->spew_utf8( $page->{'*'} );
  17. path($outfile)->touch( $dt->epoch );
  18. say STDERR sprintf( 'Succesfully fetched %s (rev. %s)',
  19. $page_title,
  20. $page->{'revid'});
  21. 1;