-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot
executable file
·52 lines (38 loc) · 1.52 KB
/
bot
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
#!/usr/bin/env python3
import asyncio
import os
import asyncpraw
class RedditBotBase(object):
"""base class for bot config"""
def __init__(self):
self.flair = None
self.user_agent = f"{os.getenv('BOT_NAME')} | {os.getenv('VERSION')} | By {os.getenv('DEVELOPER')}"
self.subreddit = os.getenv("SUBREDDIT")
self.delay = os.getenv("DELAY")
self.reddit = asyncpraw.Reddit(
client_id=os.getenv("CLIENT_ID"),
client_secret=os.getenv("CLIENT_SECRET"),
username=os.getenv("USERNAME"),
password=os.getenv("PASSWORD"),
user_agent=self.user_agent,
)
print(f"Starting up... {self.user_agent}")
# UNCOMMENT the below block to run example
# class Bot(RedditBotBase):
# """subclass RedditBotBase and include main method for processing logic"""
# async def main(self):
# print(f"...some bot is running")
# subreddit = await self.reddit.subreddit(self.subreddit)
# async for submission in subreddit.stream.submissions():
# await self.process_submission(submission)
# # sleep to avoid rate limit
# asyncio.sleep(int(self.delay))
# async def process_submission(self, submission: asyncpraw.models.Submission):
# """process submission (or any reddit object)"""
# if not submission:
# return
# print(submission.title)
# if __name__ == "__main__":
# b = Bot()
# loop = asyncio.get_event_loop()
# loop.run_until_complete(b.main())