SHARE
TWEET

Untitled

a guest Oct 4th, 2013 99 Never
  1. import praw, requests, ctypes, random, os
  2.  
  3. def downloadImage(imageUrl, localFileName):
  4.     response = requests.get(imageUrl)
  5.     if response.status_code == 200:
  6.         with open(localFileName, 'wb') as fo:
  7.             for chunk in response.iter_content(4096):
  8.                 fo.write(chunk)
  9.  
  10. r = praw.Reddit(user_agent="Wallpaper downloader")
  11. submissions = r.get_subreddit("wallpaper").get_top_from_month(limit=100)
  12. subs = [s for s in submissions]
  13. image = None
  14.  
  15. while True:
  16.     choice = random.randint(1, 100)
  17.     submission = subs[choice]
  18.     if "imgur.com/" not in submission.url:
  19.         continue
  20.     if ".jpg" in submission.url:
  21.         image = str("C:/Users/Augusto/Pictures/wallpapers/"+submission.url.replace("http://i.imgur.com/", ''))
  22.         if not os.path.isfile(image):
  23.             downloadImage(submission.url, image)
  24.         break
  25.  
  26. SPI_SETDESKWALLPAPER = 20 # According to http://support.microsoft.com/default.aspx?scid=97142
  27. ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, image, 0)
RAW Paste Data
Top