-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
55 lines (43 loc) · 1.35 KB
/
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
#!/usr/bin/env python3
import praw
import os
import time
from flask import Flask
import threading
app = Flask(__name__)
@app.route('/')
def index():
return "Reddit bot is running"
def start_flask():
app.run(host="0.0.0.0", port=8080)
def main():
flask_thread = threading.Thread(target=start_flask)
flask_thread.daemon = True
flask_thread.start()
print("Bot is starting")
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID"),
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
password=os.getenv("REDDIT_PASSWORD"),
user_agent=os.getenv("REDDIT_USER_AGENT"),
username=os.getenv("REDDIT_USERNAME"),
)
subreddit = reddit.subreddit("FUTMobile")
while True:
try:
for submission in subreddit.stream.submissions(skip_existing=True):
process_submission(submission)
except Exception as e:
print(f"Error: {e}")
time.sleep(60)
def process_submission(submission):
reply_text = "Here is the link: https://redeem.fcm.ea.com/"
title = submission.title.lower()
if "new redeem code" in title:
try:
print(f"Replying to: {submission.title}")
submission.reply(reply_text)
except Exception as e:
print(f"Failed to reply: {e}")
if __name__ == "__main__":
main()