Instantly share code, notes, and snippets.

@gtwy /watch_hockey.py Secret
Last active Dec 7, 2017

Embed
What would you like to do?
Watches /r/hockey and /r/hockeyplayers for discussions about jerseys
#!/usr/bin/env python3
# Paste this entire file into "watch_hockey.py"
# Enter your client_id and client_secret from Reddit API on lines 18 and 19.
# You can adjust your keywords on lines 21 and 22.
#
# To install:
# > chmod a+x watch_hockey.py
# > sudo apt install python3.5-dev pip pip3.5
# > sudo pip install praw
# > sudo pip3.5 install praw
#
# To run, just type:
# > ./watch_hockey.py
import praw
from datetime import datetime
client_id = "" # Enter your reddit client_id inside the quotes
client_secret = "" # Enter your reddit client_secret inside the quotes
subreddits = ["hockeyplayers", "hockey"]
keywords_hockeyplayers = ["jersy", "jersie", "jersey"]
keywords_hockey = ["custom jers"]
user_agent = "linux:sh.blindfi.bot:v0.0.1 (by /u/PCGamerJim)"
reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent)
feed = reddit.subreddit('+'.join(subreddits))
for comment in feed.stream.comments():
subreddit = comment.subreddit
text = comment.body
hide = True
if subreddit == 'hockeyplayers':
for keyword in keywords_hockeyplayers:
if keyword in text:
hide = False
if subreddit == 'hockey':
for keyword in keywords_hockey:
if keyword in text:
hide = False
if not hide:
url = "https://reddit.com//comments/{}//{}".format(comment.submission, comment.id)
try:
comment.author.name
except:
user = '(deleted)'
else:
user = comment.author.name
rtime = datetime.fromtimestamp(comment.created_utc)
print ("{} /r/{} [{}] {}\n{}\n".format(rtime.time(), subreddit, user, url, text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment