-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Hi,
I doubt this is an issue with your code but perhaps you could help since I can't seem to find anything on Google.
When testing the code in IDLE it keeps coming back with this:
Traceback (most recent call last):
File "C:\Users\thati\OneDrive\Desktop\comment.py", line 1, in
import praw
ImportError: No module named 'praw'
But I have praw installed. I've checked using help('modules') and it lists praw. I even installed using pip3. ot sure what is going on. This is a fresh install on a new PC and I haven't used python since college but it can't be that hard to install a module with the new python.
I also had to change all the "wording" to ("wording") to fix thaat syntax error and I'm not sure if that was a mistake. Again,. haven't used Python since college, which is about 9 years now.
So, minus the module issue I've made the appropriate changes, and changes I think might work (the quotes). I've changed my personal info to PERSONAL where I believe I'm supposed to add my info. Here is what I have so far:
import praw
import config
import time
import os
def bot_login():
print ("Logging in")
r = praw.Reddit(username = config.PERSONAL,
password = config.PERSONAL,
client_id = config.PERSONAL,
client_secret = config.PERSONAL,
user_agent = "The Reddit Commenter v1.0")
print ("Logged in!")
return r
def run_bot(r, comments_replied_to):
print ("Searching last 1,000 comments")
for comment in r.subreddit('test').comments(limit=1000):
if "You" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
print ("String with \"You\" found in comment ") + comment.id
comment.reply("Congrats, you are smarter than PERSONAL")
print ("Replied to comment ") + comment.id
comments_replied_to.append(comment.id)
with open ("comments_replied_to.txt", "a") as f:
f.write(comment.id + "\n")
print ("Search Completed.")
print (comments_replied_to)
print ("Sleeping for 10 seconds...")
#Sleep for 10 seconds...
time.sleep(10)
def get_saved_comments():
if not os.path.isfile("comments_replied_to.txt"):
comments_replied_to = []
else:
with open("comments_replied_to.txt", "r") as f:
comments_replied_to = f.read()
comments_replied_to = comments_replied_to.split("\n")
comments_replied_to = filter(None, comments_replied_to)
return comments_replied_to
r = bot_login()
comments_replied_to = get_saved_comments()
print (comments_replied_to)
while True:
run_bot(r, comments_replied_to)