1 1 * * * /Users/gfranxman/Pictures/ScreenSaver/ss.py
posted: 2008-04-05 02:35:56 perma-link, RSS comments feed
We just launched the new MetroPulse and I'm still in the 'keep an eye on it' mode. The site looks great and will only improve as we round out the features and their staff get more content plugged in.
One of my favorite things about the MetroPulse is their photography. And one of my favorite things about my desktop computer is that it's a mac. And one of my favorite things about macs is the unix underpinnings of OS X. And one of my favorite things about OS X is that it ships with python.
I had to do something about that.
First, I created a folder under my Pictures folder called ScreenSaver.
In there I created ss.py which contained this wonderfully simple python script:
#! /usr/bin/python import os from urllib import URLopener from urllib2 import urlopen from xml.dom.minidom import parseString rss_url = 'http://www.metropulse.com/feeds/photos/' dst_dir = os.path.expanduser('~/Pictures/ScreenSaver/' ) fd = urlopen( rss_url ) src = fd.read() fd.close() dom = parseString( src ) for i,e in enumerate( dom.getElementsByTagName( 'item' ) ): enclosure = e.getElementsByTagName( 'enclosure' )[0] link = enclosure.getAttribute( 'url' ) mime = enclosure.getAttribute( 'type' ) ext = mime[ mime.index('/')+1:] URLopener().retrieve( link, filename="%s%s.%s" % (dst_dir,i,ext) )
Next I created a new file called sscron to run hold a schedule for running that python script:
1 1 * * * /Users/gfranxman/Pictures/ScreenSaver/ss.py
( If you are playing along at home, you'll need to change the 'gfranxman' to your own user name. )
And then I marked the script executable, gave a whirl, and installed the schedule by opening the terminal executing:
$ chmod u+x ~/Pictures/ScreenSaver/ss.py $ ~/Pictures/ScreenSaver/ss.py $ crontab ~/Pictures/ScreenSaver/sscron
Finally, I opened the system prefereces, went to the ScreenSaver preferences and clicked 'Choose Folder'. After selecting my Pictures/ScreenSaver folder, I now a screen saver of the latest 20 photos posted to the MetroPulse website, refreshed daily and displayed with that gratuitous Ken Burns effect.
Glenn commented, on April 5, 2008 at 10:05 a.m.:
OK, I've pumped up the contrast on the code sections.
Re: macs == satan
Come on, you're the one who got me started on Apple. Indirectly, this is all your fault!
Justin commented, on April 6, 2008 at 9:25 a.m.:
I'm only commenting because I'm curious what my avatar will look like.
Clark commented, on April 7, 2008 at 12:09 p.m.:
macs <> satan
Jobs == satan
Now that I can read your code I feel inferior for not understanding it. Make it dark and illegible again so as to spare my frail psyche.
Ryan commented, on April 7, 2008 at 1:51 p.m.:
Could this script work with a Flickr RSS feed? The code looks easy enough to modify (from my non-programmer perspective) to work with Flickr...
Glenn commented, on May 3, 2008 at 5:08 a.m.:
I imagine it would work with flickr -- there are lots of flickr screensavers out there.
Right now, I'm geeked on finally getting some code highlighting working on here.
Keith commented, on January 3, 2009 at 9:59 p.m.:
Thanks for this script - just what I was looking for!
|
Based upon your reading habits, might I recommend: Or, you might like: |
hosting: slicehost.com.
powered by: django.
written in: python.
controlled by: bzr.
monsters by: monsterID.
You've been exposed to: {'Programming': 1}
Clark commented, on April 5, 2008 at 8:47 a.m.:
Dude... Not that I would understand it if I could see it... but black text on a dark gray background is a tad difficult to read.
MetroPulse looks cool...
Macs are spawn of the devil... and not the cool robot devil.