I read the MediaWiki API documentation but I cannot find how to get the current URL of the picture of the day.
Following RTFM, I call the query from Commons:Potd to its page URL.
It returns pageid=2518149
, it is the current POTD page.
Then I try to call prop=imageinfo
, but I didn't find the way to get the image URL.
The only successful call is this:
http://commons.wikimedia.org/w/api.php?titles=File:POTD&action=query&prop=images
"Successful" means it returns an image URL ... but of a different pageid
(not the current POTD)!
Hmm, this isn't very easy. You're not getting anything back from
Commons:Potd
because that's just a redirect, but even if you fetch images fromCommons:Picture of the Day
, you just get a huge list of all images ever in alphabetical order.But here's one solution. First expand the Potd template to figure out the current image name:
http://commons.wikimedia.org/w/api.php?action=expandtemplates&text={{Potd/{{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY2}}}}
Then plug that filename (URL-encoded) into a separate request to imageinfo, with
iiprop=url
to get the URL:http://commons.wikimedia.org/w/api.php?titles=Image:20110421%20Tbilisi%20Georgia%20Panoramic.jpg&action=query&prop=imageinfo&iiprop=url
And there it is!
The picture file itself can be retrieved using the value of the
url
attribute: