Reputation: 604
How do I modify the example at https://commons.wikimedia.org/wiki/Commons:API/MediaWiki#Get_files_uploaded_by_a_particular_user to also list the categories each page is in, the wikitext of the page, and perhaps even some of the Structured Data?
Upvotes: 1
Views: 212
Reputation: 604
OK, I'm rather happy with:
$ cat Makefile
texts:wikitext list.json
./j2s $?|(cd $< && sh -ex)
wikitext:; mkdir $@
list.json: #https://www.mediawiki.org/wiki/API:Allimages
GET 'https://commons.wikimedia.org/w/api.php?action=query$(\
)&list=allimages&aiuser=Jidanni&aisort=timestamp$(\
)&format=json&aiprop=url$(\
)&aidir=descending&ailimit=4' > $@
$ cat j2s
#!/usr/bin/perl
use strict;
use warnings FATAL => q(all); #old fashioned, yes
use JSON;
use open qw/:std :encoding(utf8)/;
my $j;
while (<>) { $j .= $_ }
my $p = decode_json $j;
for ( @{ $p->{query}->{allimages} } ) {
my $f = $_->{name};
if ( $f =~ /"/ ) {
die "Oh man, even a double quote in my the proposed filename, $f.";
}
$f =~ s/\.jpg$/.txt/;
printf "
if ! test -f \"%s\"
then wget --no-verbose --output-document \"%s\" \"%s%s\"; sleep 1
fi
", ($f) x 2, $_->{descriptionurl}, "?action=raw";
}
Note also https://www.mediawiki.org/wiki/API_talk:Main_page#Wikitext_of_all_matching_pages
Upvotes: 0