Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import string
- import time
- import praw
- import shutil
- import requests
- reddit = praw.Reddit(
- client_id="clientid",
- client_secret="secret",
- user_agent="agent"
- )
- print("Logged in successfully.") if reddit.read_only is True else print("Error logging in.")
- temp_user = input("Please specify the user (just the username, do not include \"u/\"): ")
- user = reddit.redditor(temp_user)
- def scrape_user(user):
- submissions = user.submissions.new(limit=10)
- for submission in submissions:
- if submission.is_self:
- save_txt(submission.title + " : " + submission.selftext + "\n \n")
- else:
- save_img(submission.url)
- def save_img(url):
- print("Saving img")
- response = requests.get(url, stream=True)
- if any(file_type in url for file_type in ['.jpeg', '.jpg', '.png']):
- with open(''.join(random.choices(string.ascii_lowercase, k=5)) + '.jpeg', 'wb') as out_file:
- shutil.copyfileobj(response.raw, out_file)
- del response
- else:
- print("Not an img, skipping")
- def save_txt(text):
- print("Saving text")
- with open('saved_text.txt', 'a') as f:
- f.write(text)
- while True:
- scrape_user(user)
- print("Done, sleeping for 15 mins")
- time.sleep(900) # 15 mins
Advertisement
Add Comment
Please, Sign In to add comment