-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedditTestBot.py
More file actions
117 lines (96 loc) · 3.6 KB
/
RedditTestBot.py
File metadata and controls
117 lines (96 loc) · 3.6 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import praw
import sys
import time
import threading
import urllib
import configparser
from random import *
config = configparser.ConfigParser()
config.read('my.ini')
# login info
proceed = False
ID = config.get('Authentication', 'Client_id')
SECRET = config.get('Authentication', 'Client_secret')
USERNAME = config.get('Authentication', 'Username')
PASSWORD = config.get('Authentication', 'Password')
USER_AGENT = config.get('Authentication', 'User_agent')
# phrases to reply with
PHRASES = ["Stay strong my friend", "I am glad you are with us", "Keep your head up",
"Try your best to get through this!", "We are all with you", "Never give up!"]
phrases_to_look_for = ["I am depressed", "I am feeling depressed", "I want to commit suicide",
"thinking about suicide", "do not want to live", "I have deppresion",
"I'm depressed", "i have deppresion", "kill myself", "no pleasure",
"I can't imagine going on", "I'm really scared", "I am scared", "I'm scared"]
# creating of the praw object, logging in and continious while
def main():
reddit = praw.Reddit(client_id=ID ,
client_secret=SECRET,
username=USERNAME,
password=PASSWORD,
user_agent=USER_AGENT)
print("Logged in", file=sys.stderr)
# separate thread which will delete downvoted comments made by this bot
# navigating through depression subreddit
#subreddit = reddit.subreddit('depression')
#hot_depression = subreddit.hot(limit=1000)
# old comment scanner/deleter
t = threading.Thread(target=delete_downvoted_posts, args=(reddit,))
t.start()
while (True):
print("Beginning to look through reddit", file=sys.stderr)
depression_scanner(reddit, phrases_to_look_for)
print("Taking a 15 second break", file=sys.stderr)
time.sleep(15)
print("I've done my job", file=sys.stderr)
def depression_scanner(session, phrases):
reddit_all1 = session.subreddit('all')
reddit_all = reddit_all1.new(limit=1000)
print("Fetching posts", file=sys.stderr)
comment_count = 0
proceed = False
for submission in reddit_all:
if not submission.stickied:
comment_count += 1
if not submission.visited:
for phrase in phrases_to_look_for:
if phrase in submission.selftext:
print("Deppressed post found", file=sys.stderr)
if len(submission.comments) >= 1:
for reply in submission.comments:
if reply.author.name == "shokhan768" or reply.author.name == 'depressagent':
print("Already posted in this thread", file=sys.stderr)
proceed = False
break
else:
proceed = True
else:
proceed = True
if proceed == True:
print("Deppressed thread found", file=sys.stderr)
post_motivation(submission)
print("Motivation posted", file=sys.stderr)
break
if comment_count == 1000:
return
def post_motivation(reply_to):
try:
print("Posting motiivational response", file=sys.stderr)
rand_int = randint(0, len(PHRASES))
motivation = PHRASES[rand_int]
reply_to.reply(motivation)
except Exception as e:
print("Something went wrong", file=sys.stderr)
def delete_downvoted_posts(session):
while True:
print("Looking through old comments", file=sys.stderr)
my_account = session.redditor(USERNAME)
my_comments = my_account.comments.new()
for old_comment in my_comments:
if old_comment.score < 0:
print("Comment taken badly... removing", file=sys.stderr)
old_comment.delete()
# sleep for half hour
print("Turning off old comment scanner for 30 mins", file=sys.stderr)
time.sleep(1800)
if __name__ == '__main__':
main()