Skip to content

Instantly share code, notes, and snippets.

@sauravtom
Created May 14, 2017 06:12
Show Gist options
  • Save sauravtom/469a42510bf46e934424f6fd04e9ac20 to your computer and use it in GitHub Desktop.
Save sauravtom/469a42510bf46e934424f6fd04e9ac20 to your computer and use it in GitHub Desktop.
import os
import feedparser
import urllib
import time
from random import randint
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
def changeBG(file_name):
os.system('''
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "%s/wallpapers/%s"'
'''%(DIR_PATH,file_name)
)
def unsplash():
d = feedparser.parse('https://unsplash.com/rss')
r = randint(0,len(d['entries'])-1)
image_url = d['entries'][r]['url']
epoch = str(int(time.time()*100))
file_name = 'image_%s.png'%(epoch)
os.system('wget "%s" -O %s/wallpapers/%s'%(image_url,DIR_PATH,file_name))
changeBG(file_name)
def instagram():
d=feedparser.parse('http://blog.instagram.com/tagged/photo_feature/rss')
print len(d['entries'])
print d['entries'][0]['description']
def folder():
images = [i for i in os.listdir("%s/wallpapers"%DIR_PATH) if i!='.DS_Store']
r = randint(0,len(images)-1)
random_image = images[r]
changeBG(random_image)
if __name__ == '__main__':
folder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment