Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw, requests, ctypes, random, os
- def downloadImage(imageUrl, localFileName):
- response = requests.get(imageUrl)
- if response.status_code == 200:
- with open(localFileName, 'wb') as fo:
- for chunk in response.iter_content(4096):
- fo.write(chunk)
- r = praw.Reddit(user_agent="Wallpaper downloader")
- submissions = r.get_subreddit("wallpaper").get_top_from_month(limit=100)
- subs = [s for s in submissions]
- image = None
- while True:
- choice = random.randint(1, 100)
- submission = subs[choice]
- if "imgur.com/" not in submission.url:
- continue
- if ".jpg" in submission.url:
- image = str("C:/Users/Augusto/Pictures/wallpapers/"+submission.url.replace("http://i.imgur.com/", ''))
- if not os.path.isfile(image):
- downloadImage(submission.url, image)
- break
- SPI_SETDESKWALLPAPER = 20 # According to http://support.microsoft.com/default.aspx?scid=97142
- ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement