Skip to content

Instantly share code, notes, and snippets.

@bchauSW
Last active July 18, 2019 04:00
Show Gist options
  • Save bchauSW/49823e399e37c002cc779d9ed059565e to your computer and use it in GitHub Desktop.
Save bchauSW/49823e399e37c002cc779d9ed059565e to your computer and use it in GitHub Desktop.
This script finds a person who posts to two specified subreddits.
import praw
reddit = praw.Reddit(client_id='clientid',
client_secret='clientsecret',
password='password',
user_agent='Script by me',
username='username')
checked_users = []
with open('users.txt', 'w+') as f:
for submission in reddit.subreddit('askreddit').top(limit=100):
author = submission.author
if not author is None and author.name not in checked_users:
checked_users.append(author.name)
redditor_submissions = author.submissions.hot(limit=100)
for r_submission in redditor_submissions:
if r_submission.subreddit == 'strangerthings' and not r_submission.is_self:
f.write(author.name + '\n')
f.write('First Link: ' + submission.subreddit.name + '\n')
f.write('Second Link: ' + r_submission.subreddit.name + '\n\n')
print(author.name)
break
@JeromeLC
Copy link

Could you provide more information on how to use this script? I have replaced both 'subreddit' & 'another subreddit' with subs i have posted in recently and cannot get the script to return any results.

@bchauSW
Copy link
Author

bchauSW commented Jul 17, 2019

Could you provide more information on how to use this script? I have replaced both 'subreddit' & 'another subreddit' with subs i have posted in recently and cannot get the script to return any results.

I missed the 'name' field when writing the subreddit name to the file, which may have caused the issue.

Trying the example that I have now, it should return /u/-eDgAR- as one of the results.

@bchauSW
Copy link
Author

bchauSW commented Jul 17, 2019

You will also need to register your own app with Reddit via this link, and replace the data at the top of the script with your own credentials.

@JeromeLC
Copy link

I was able to get it to work as expected. Thank you.

What are the do the values of "First Link & Second Link" represent?
-eDgAR-
First Link: t5_2qh1i
Second Link: t5_3adlm

@bchauSW
Copy link
Author

bchauSW commented Jul 18, 2019

The links seem to point to the link to the post. By using "submission.subreddit.name", it will display the subreddit of the submission.

Here is the link to the PRAW documentation for more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment