import re,os,json,requests,urllib.request URL = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1" dir_path = os.environ['HOME'] + '/Pictures/Bing_Pic_of_the_Day/' if __name__ == '__main__': try: image_data = json.loads(requests.get(URL).text) image_url = 'http://www.bing.com' + image_data['images'][0]['url'] _image_name_arr = image_url.split("&") __image_name_arr = _image_name_arr[0].split("?") image_name = re.sub(r'^id\=',"",__image_name_arr[1]) if not os.path.exists(dir_path): os.makedirs(dir_path) file_path = dir_path + image_name if os.path.exists(file_path) is False: urllib.request.urlretrieve(image_url, filename=file_path) image_desc = image_data['images'][0]['copyright'] command = 'gsettings set org.gnome.desktop.background picture-uri file://' + file_path os.system(command) notify = 'notify-send -u critical "Wallpaper for the Day updated!" "' + image_desc + '"' os.system(notify) else: notify = 'notify-send -u critical "Bing Wallpaper" "Wallpaper for the day has been updated already!"' os.system(notify) except: notify = 'notify-send -u critical "Bing Wallpaper" "Wallpaper can\'t be updated!"' os.system(notify)