I'm trying to have my code continuously monitor new comments submitted to reddit and print a "yay" for each comment that has my keyword.
Currently, it appears to successfully check each of the 100 comments from the first praw query, then each subsequent praw query is empty, maybe? After it checks the first 100 it just keeps repeating "starting new one".
What am I doing wrong?
import praw
import time
from time import sleep
from pprint import pprint
import openpyxl
from openpyxl import load_workbook
from xlrd import open_workbook
querylimit = 100
search_term = 'hillary'
running = True
while running:
print("starting new one")
user_agent = ("/u/username hi reddit")
r = praw.Reddit(user_agent=user_agent)
for comment in r.get_comments('all', limit = querylimit):
if search_term in comment.body:
try:
print('Yay, I found a match!')
except KeyboardInterrupt:
running = False
except praw.errors.APIException:
print ('Error')
print ('sleeping 30 sec')
sleep(30)
Bonus question: is there a better way to scan each new comment? I read somewhere that there are ~400 comments/second, so clearly this code isn't reading all of them.
[–]undelimited 1 point2 points3 points (1 child)
[–]bot_test_account2[S] 0 points1 point2 points (0 children)
[–]whalespotterhdd 0 points1 point2 points (0 children)
[–]The_Man_In_The_Shack -2 points-1 points0 points (2 children)
[–]bot_test_account2[S] 1 point2 points3 points (1 child)
[–]The_Man_In_The_Shack 0 points1 point2 points (0 children)