Skip to content

Instantly share code, notes, and snippets.

@dennis90
Created August 7, 2017 16:04
Show Gist options
  • Save dennis90/83364ecc19a81189cfda3c4ba28f84b9 to your computer and use it in GitHub Desktop.
Save dennis90/83364ecc19a81189cfda3c4ba28f84b9 to your computer and use it in GitHub Desktop.
Download wallpaper of the day at bing and set as wallpaper in xfce4
import os
import urllib
import json
from urllib.parse import urlparse
from urllib import request
"""
This script downloads bing's image of the day on the specified folder and set it as wallpaper in xfce4
"""
IMAGES_DIR = "%s/Imagens/wallpapers" % os.getenv("HOME")
API_URL = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=pt-BR"
API_ROOT_URL = "http://www.bing.com"
content = request.urlopen(API_URL)
content = json.loads(content.read().decode('utf-8'))
image_url = "%s%s" % (API_ROOT_URL, content['images'][0]['url'])
image_filename = os.path.basename(urlparse(image_url).path)
output_path = "%s/%s" % (IMAGES_DIR, image_filename)
request.urlretrieve(image_url, output_path)
os.system("xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/last-image --set %s" % output_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment