View Full Version : Python Picture of the Day

June 19th, 2009, 02:52 AM
Here's a short script that grabs the Wikipedia Picture of the Day:


import urllib2

potdMeta = urllib2.urlopen('http://toolserver.org/~daniel/potd/commons/potd.meta.xml')
potdURL = potdMeta.read().split('url="')[1].split('"')[0]
potdRequest = urllib2.Request(potdURL)
potd = urllib2.build_opener().open(potdRequest)
f = open('./potd.jpg','wb')

Just a fun script. :)

June 19th, 2009, 09:54 AM
You may want to change the 'w' in the open function call to 'wb', to prevent the os from potentially changing percieved line endings in the jpeg file.
Nice though!

EDIT: I implemented this with an xml parser also, just to see how much work it would be - turns out it isn't worth it.

June 19th, 2009, 03:47 PM
I made it so I can make my own homepage like Google/ig or bing. Here's a script for getting the top headlines from wikinews:


import urllib2

wikinews = urllib2.urlopen('http://feeds.feedburner.com/WikinewsLatestNews')
newsItems = wikinews.read().split('<item>')[1:5]
for newsItem in newsItems:
title = newsItem.split('<title>')[1].split('</title>')[0]
print title
link = newsItem.split('<link>')[1].split('</link>')[0]
print link

It just prints them, but it would be easy to do something else with them. :)