-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreddit_bot.py
37 lines (31 loc) · 1.1 KB
/
reddit_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import praw
from random import randint
from main import Chatbot
import os
import yaml
CONFIG_PATH = "."
chatbot = Chatbot(CONFIG_PATH)
with open(os.path.join(CONFIG_PATH,"reddit_credentials.yml")) as cf:
reddit_cred = yaml.load(cf, Loader=yaml.FullLoader)
client_id = reddit_cred["client_id"]
client_secret = reddit_cred["client_secret"]
username = reddit_cred["username"]
password = reddit_cred["password"]
user_agent = reddit_cred["user_agent"]
subreddit = reddit_cred["subreddit"]
reddit = praw.Reddit(client_id=client_id,
client_secret=client_secret,
username=username,
password=password,
user_agent=user_agent)
subreddit = reddit.subreddit(subreddit)
print("Reddit B0t is live")
for comment in subreddit.stream.comments(skip_existing=True):
if comment.author == username:
continue
reply_text , _ , _ , _= chatbot.reply(comment.body)
try:
comment.reply(reply_text)
print('Replied')
except:
print('There is some issue bro.')