Skip to content

Instantly share code, notes, and snippets.

@gtwy
Last active December 7, 2017 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtwy/9eb7510df922acaf60f9a2446708d3fc to your computer and use it in GitHub Desktop.
Save gtwy/9eb7510df922acaf60f9a2446708d3fc to your computer and use it in GitHub Desktop.
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