joesv

Download stuff bot

May 28th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import praw
  2. import urllib.request
  3. import os
  4. import time
  5.  
  6. path = "F:/wallpapers/redditautodownload/"
  7. user_agent = ("Background downloader made by /u/joesv 0.1")
  8. def download(string):
  9.     r = praw.Reddit(user_agent = user_agent)
  10.     subreddit = r.get_subreddit(string)
  11.     urls = []
  12.     for submission in subreddit.get_hot(limit = 10):
  13.         if "imgur.com" in submission.url:
  14.             urls.append(submission.url)
  15.     print(urls)
  16.  
  17.  
  18.  
  19.     for i in range(0, len(urls)):
  20.         if not ".jpg" in urls[i]:
  21.             urls[i] = urls[i] + ".jpg"
  22.             print(urls[i])
  23.         if not os.path.isfile(urls[i][19:]):
  24.             urllib.request.urlretrieve(urls[i], os.path.join(path + urls[i][19:]))
  25.  
  26. while True:
  27.     download("earthporn")
  28.     time.sleep(600)
Add Comment
Please, Sign In to add comment