Skip to content

Commit 9b2cb75

Browse files
committed
major bug fix, recommenting on trigger & crash err
1 parent a8b1767 commit 9b2cb75

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

script.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import collections
77
import time
8+
import json
89

910
# Open the text file containing the words
1011
with open('wholesomewords.txt', 'r') as f:
@@ -32,7 +33,7 @@
3233
cache = {}
3334

3435
# Subreddit and trigger phrase
35-
subreddit_names = "IndianTeenagers, flatapartmentcheck, JEENEETards"
36+
subreddit_names = "flatapartmentcheck+IndianTeenagers+JEENEETards"
3637
trigger_phrases = ['!wholesomenesscheck',
3738
'!wholesomecheck', '!uwucheck', '!uwucheckself']
3839

@@ -43,7 +44,7 @@
4344
comments_to_reply = []
4445
for subreddit_name in subreddit_names:
4546
subreddit = reddit.subreddit(
46-
"IndianTeenagers+flatapartmentcheck+JEENEETards")
47+
"flatapartmentcheck+IndianTeenagers+JEENEETards")
4748
for incoming_comment in subreddit.stream.comments(skip_existing=True):
4849
# Check if comment contains any of the trigger phrases
4950
if any(phrase in incoming_comment.body.lower() for phrase in trigger_phrases):
@@ -75,11 +76,16 @@
7576
else:
7677
# Make API request for user comments
7778
url = f'https://api.pushshift.io/reddit/comment/search?html_decode=true&after=0&author={user_name}&size=500'
78-
with requests.Session() as session:
79-
response = session.get(url)
80-
# Add a sleep of 10 seconds after each API request
81-
time.sleep(10)
82-
api_comments = response.json()['data']
79+
try:
80+
with requests.Session() as session:
81+
response = session.get(url)
82+
# Add a sleep of 7 seconds after each API request
83+
time.sleep(7)
84+
api_comments = response.json()['data']
85+
except (requests.exceptions.RequestException, json.JSONDecodeError) as e:
86+
print(
87+
f"Error occurred while making the API request: {e}")
88+
api_comments = []
8389

8490
# Store response in cache
8591
cache[user_name] = {
@@ -117,4 +123,7 @@
117123
reply_text = f'The number of wholesome occurrences in the recent 500 comments of u/{user_name} is {wholesome_count}.\n\n| Word | Count |\n| --- | --- |\n{table} |\n\nStay wholesome! \n\nWanna do something even more wholesome? Leave a \u2B50 at the [GitHub repository](https://github.com/MeowthyVoyager/reddit-wholesome-counter).'
118124

119125
# Add comment to list of comments to reply to
126+
comments_to_reply.append((incoming_comment, reply_text))
127+
128+
# Call reply() on the comment immediately
120129
incoming_comment.reply(reply_text)

wholesomewords.txt

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ awwwwww
1111
awwwwwww
1212
awwwwwwww
1313
awwwwwwwww
14+
awwwwwwwwww
15+
awwwwwwwwwww
16+
awwwwwwwwwwww
17+
awwwwwwwwwwwww
18+
awwwwwwwwwwwwww
19+
awwwwwwwwwwwwwww
1420
thanks
21+
thx
22+
thsm
1523
np
1624
noproblem
1725
love
@@ -25,6 +33,7 @@ vibe
2533
happy
2634
wholesome
2735
cuddly
36+
mew
2837
meow
2938
meoww
3039
meowwww
@@ -45,5 +54,16 @@ slay
4554
slayy
4655
slayyy
4756
slayyyy
57+
slayyyyy
4858
bright
49-
warmth
59+
warmth
60+
cat
61+
ily
62+
faith
63+
positivity
64+
positively
65+
optimistic
66+
hopeful
67+
cheer
68+
congratulations
69+
contraz

0 commit comments

Comments
 (0)