Flickr Wallpapers daily for Linux Mint & Ubuntu

Linux has very few options for ‘Automatic Wallpaper Setter’. Variety is at the top. I loved it, it has lots of image sources, effects, a digital clock and daily quotes. You can also set your wallpaper-switching interval. It is really worth checking out. But what I wanted was a simple script that would download images from Flickr daily and set them as my desktop wallpaper. So here is the Python script to download and set wallpapers on Linux Mint and Ubuntu from Flickr based on an image’s interestingness.

So, to get a list of interesting photos from Flickr we will require Flickr API keys (used strictly for non-commercial use). You can get them from here. The API we are going to use for our script is : flickr.interestingness.getList more info about this API can be found here. You can set its arguments as per your requirements. For this script, I am requesting the response in XML format but you can also get it in JSON. When we are done with tuning the API it would look something like this.

(You need put your API key there…). The above REST request doesn’t actually return an image URL but it returns Image IDs, Server IDs and Secret alphanumeric IDs of interesting images as per your limit (in this case 5) and date. Now our job is to map these image IDs to their respective static URLs so that it will be convenient for us to download them.

With the help of the above API, we can construct the source URLs of the images. At the tail of this API, we need to specify the size of the image we want to download. More info about this can be found here.

Let’s get back to our script. We need to select a date for retrieving interesting images on that date. Ideally, this date should be at least two days before. The limit for retrieving the number of images should be around five as you will need only one wallpaper daily. We will now generate our API URL and request it via HTTP request which will return us an XML response which we have to parse (Sample XML Response from the Flickr Interesting API can be found here). Parsing XML in Python is quite simple and can be done with ElementTree XML . After parsing the response we have to save all of its necessary attributes in independent variables and also replace any whitespaces with an underscore (to avoid any kind of conflicts while setting the wallpaper). With the help of these attributes we will generate our static URLs and add them in List[]. Also, we will create a Dictionary{} to maintain a mapping between image titles and URLs {'photo_url': 'photo_title'}.

So, we have five image URLs in a list and we can choose any one randomly (if you want) to set as our wallpaper. Once we have our desired image URL we can download the image file and save it in a directory. In this script, I have set the download directory as: ~/Pictures/Flickr/

If this download directory doesn’t exist it will be created so that images can be saved there (in .jpg format). This script is specifically targeted to Cinnamon Desktop Environment [Linux Mint 17.X]. Wallpapers can be changed in Cinnamon as follows:

Now this script sets wallpaper only if there is no image for that day in the download directory, but you can change that logic according to your preferences. To automate this script ie. to execute it whenever you are connected to the internet you can try this software Cuttlefish. More info about Cuttlefish at Ubuntu handbook and OMGUbuntu. If you want to do it the hard way refer the Ubuntu guide for OnNetworkConnectionRunScript and this post on AskUbuntu.

This slideshow requires JavaScript.

This script is available on Github you can modify it as per your needs. If you encounter any bugs let me now.