-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreddit-relationships-bot.py
107 lines (95 loc) · 2.86 KB
/
reddit-relationships-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
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
import os
import praw
from settings import SETTINGS
reddit = praw.Reddit(client_id=SETTINGS['REDDIT_CLIENT_ID'],
client_secret=SETTINGS['REDDIT_CLIENT_SECRET'],
user_agent=SETTINGS['REDDIT_USER_AGENT'])
subreddit = reddit.subreddit('relationships')
cliches = [
{
"advice": "Break up",
"spellings": ["divorce", "break up", "leave him", "leave her"],
"comments": [],
},
{
"advice": "Get your ducks in a row",
"spellings": ["ducks in a row"],
"comments": [],
},
{
"advice": "Don't JADE",
"spellings": ["jade"],
"comments": [],
},
{
"advice": "Grey rock",
"spellings": ["grey rock", "grey-rock", "gray rock", "gray-rock"],
"comments": [],
},
{
"advice": "Consult a lawyer",
"spellings": ["lawyer"],
"comments": [],
},
{
"advice": "Go no-contact",
"spellings": ["no contact", "no-contact"],
"comments": [],
},
{
"advice": "Love languages",
"spellings": ["love language"],
"comments": [],
},
{
"advice": "Low-contact",
"spellings": ["low contact", "low-contact"],
"comments": [],
},
{
"advice": "\"No\" is a complete sentence",
"spellings": ["no is a complete sentence", "\"no\" is a complete sentence"],
"comments": [],
},
{
"advice": "Red flag",
"spellings": ["red flag"],
"comments": [],
},
{
"advice": "Get therapy / counselling",
"spellings": ["therapy", "counselling"],
"comments": [],
},
{
"advice": "Hit the gym",
"spellings": ["hit the gym", "go the the gym", "going to the gym"],
"comments": [],
},
{
"advice": "Narcissist",
"spellings": ["narcissist", "narcisist", "narcissism", "narcisism"],
"comments": [],
},
]
def display_information():
os.system('cls' if os.name == 'nt' else 'clear')
print "Analysing %d submissions for cliches" % (SETTINGS["SUBMISSIONS_TO_ANALYSE"])
print "Analysed %d comments from %s submissions\n" % (comments_analysed, submissions_analysed + 1)
for cliche in cliches:
print "%s: %s" % (cliche['advice'], len(cliche['comments']))
def analyse_comment(comment):
for cliche in cliches:
for spelling in cliche['spellings']:
if hasattr(comment, 'body') and spelling in comment.body.lower():
cliche['comments'].append(comment.id)
submissions = subreddit.hot(limit=SETTINGS["SUBMISSIONS_TO_ANALYSE"])
submissions_analysed = 0
comments_analysed = 0
for submission in submissions:
for comment in submission.comments.list():
analyse_comment(comment)
comments_analysed += 1
display_information()
submissions_analysed += 1
print "\nComplete."