-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot0.py
More file actions
93 lines (83 loc) · 3.17 KB
/
bot0.py
File metadata and controls
93 lines (83 loc) · 3.17 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
# script runs CheerB0t to check all comments on reddit (besides blacklisted subreddits)
import praw
import json
import nltk
import random
def botLogin():
bot = praw.Reddit(client_id='CTiJ3GSR0H4oHg',
client_secret='-U3YrdWAcoNfYKBMIPeowDzDbmc',
user_agent='cheerb0t',
username='cheerb0t',
password='')
return bot
def getImg(bot):
funsub = bot.subreddit('wholesomecomics')
posts = funsub.top(limit=60)
ranNum = random.randint(0,59)
for i,post in enumerate(posts):
if i==ranNum:
return post.url
def getMsg():
msgNum = random.randint(0,8)
if msgNum == 0:
message = " [Maybe this will cheer you up?]("
elif msgNum == 1:
message = " [Maybe this comic will cheer you?]("
elif msgNum == 2:
message = " [Here's something to cheer you up.]("
elif msgNum == 3:
message = " [Here's a comic for you.]("
elif msgNum == 4:
message = " [Maybe this can brighten your day.]("
elif msgNum == 5:
message = " [Maybe this can lighten the mood.]("
elif msgNum == 6:
message = " [Maybe this can make you feel better.]("
elif msgNum == 7:
message = " [Hopefully this cheers you up.]("
else:
message = " [Maybe this will cheer you up?]("
return message
bot = botLogin()
file = open("stress.json");
reader = file.read()
data = json.loads(reader)
subreddit = bot.subreddit('all')
blacklist = {'askreddit','funny','gaming','news','the_donald','dankmemes','television',
'globaloffensive','2007scape','pathofexile','warframe','nfl','overwatch',
'gameofthrones','anime','comicbooks','starwars','pubattlegrounds','games',
'prequelmemes','warframe','hearthstone','4chan','rainbow6','starwarsbattlefront',
'leagueoflegends','magictcg','greenday','copypasta','buffalobills','offmychest',
'wrestlingisreddit'}
comments = subreddit.stream.comments()
for comment in comments:
if comment.subreddit.display_name.lower() in blacklist:
continue
wordList = []
totScore = 0
totWords = 0
comp = 0
str = (comment.body).lower()
totWords = len(str.split())
tokens = nltk.word_tokenize(str)
# print submission.title, ' >>> ', totWords
for token in tokens:
if token in data and token not in wordList:
totScore += int(data[token])
wordList.append(token)
wordList.append(data[token])
comp = float(totScore)/float(totWords)
if totScore < -22 and comp < -0.17:
message = "{0}, your post indicated a high level of stress.\n".format(comment.author)
message += getMsg()
message += getImg(bot)+")\n\n ^-automated ^message ^by ^bot"
comment.reply(message)
print ('Commented in ',comment.subreddit)
# print '\n TESTER:'
# print comment.subreddit
# print comment.author
# print comment.body
print wordList
print totScore
print comp
# print message