Well I’m now trying to publish here some of the tools I use and write everyday to customize my desktop, most of them are simple hacks, this time it’s a way to set your desktop background from a Flickr feed that is requested to be filtered using some tags.
Heres the code:
-
#!/usr/bin/python
-
-
import feedparser
-
import urllib
-
import random
-
FLCKR_API = "http://api.flickr.com/services/feeds/photos_public.gne"
-
TAGS = "fantasy,nature,night,dog,art,beach"
-
-
query = urllib.urlencode(((‘tags’,TAGS),(‘tagmode’,‘any’)))
-
entries = feedparser.parse("%s?%s" % (FLCKR_API,query))
-
links = []
-
for entry in entries[‘entries’]:
-
for href in entry[‘links’]:
-
if "image" in href[‘type’]:
-
links.append(href[‘href’])
-
-
print random.choice(links)
-
You should set TAGS=”" to the tags you want to filter the backgrounds.
Now to use it I have the following script that I tried to make smart enough to notice when I have a dual head setup and grabs two images and makes a composition so I will have a different background on each monitor, it works nice but it has its problems.
-
#!/bin/sh
-
-
TOT=`wc -l ~/New.list | cut -f1 -d" "`
-
if [ -f /tmp/flickr ]; then
-
wget `flickrget` -O /tmp/bg1.jpg > /dev/null 2>&1
-
BG1="/tmp/bg1.jpg"
-
else
-
BG1=`sed -n $[RANDOM % TOT]p ~/New.list`
-
fi
-
DIMENSIONS=`xdpyinfo | grep dimensions | sed s/".* \([0-9]*x[0-9]*\) pixels.*"/"\1"/`
-
-
if [ "$DIMENSIONS" == "1440×900" ]; then
-
Esetroot -f $BG1
-
else
-
if [ -f /tmp/flickr ]; then
-
wget `flickrget` -O /tmp/bg2.jpg > /dev/null 2>&1
-
BG2="/tmp/bg2.jpg"
-
else
-
BG2=`sed -n $[RANDOM % TOT]p ~/New.list`
-
fi
-
nice -20 montage -background black -geometry 1440×900 $BG1 $BG2 /tmp/cur_bg.bmp
-
-
Esetroot -c /tmp/cur_bg.bmp
-
fi
-
There are several things on the previous scripts that should be tweaked, first ~/New.list it’s a list of my local list of backgrounds, 1440×900 it’s my laptop internal video size, /tmp/flickr it’s a file I use to control the source of my desktop backgrounds and finally flickrget its the name I choose for the previous python script and set it on my path.
I have setup the shell script on my awesome client to be run every 30 minutes so I get a new background after that time but also a button on my status bar to force a change when I don’t like the background it choose for me.
EOP
Tags: awesome · backgrounds · bash · desktop · Esetroot · Eterm · flickr · pythonComments





