Last active
July 7, 2019 22:30
-
-
Save bchauSW/74e486c2e86c1ed26bbdeed1267fc723 to your computer and use it in GitHub Desktop.
This script is triggered when a user is tagged in a news article submission comment, extracts the comment, and PM's the article to the tagging user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import praw | |
import re | |
from praw.models import Comment | |
from newspaper import Article | |
import time | |
uname = 'username' | |
reddit = praw.Reddit(client_id='clientid', | |
client_secret='clientsecret', | |
password='password', | |
user_agent='Script by me', | |
username=uname) | |
while True: | |
unread_messages = [] | |
for item in reddit.inbox.unread(limit=None): | |
if isinstance(item, Comment): | |
submission = item.submission | |
comment_body = item.body | |
print(comment_body) | |
if not submission.is_self and comment_body == "/u/" + uname: | |
url = submission.url | |
article = Article(url) | |
article.download() | |
article.parse() | |
reddit.redditor(item.author.name).message(article.title, article.text) | |
unread_messages.append(item) | |
reddit.inbox.mark_read(unread_messages) | |
time.sleep(300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment