-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (53 loc) · 1.98 KB
/
main.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
#!/usr/bin/env python3
from decouple import config
from datetime import datetime
from pathlib import Path, PurePath
import time
import praw
import openai
import random
from bot_helper import get_bots, login, HOURLY_COMMENTS, HOURLY_POSTS
from list_helper import get_timecode, get_brands, get_sublist
from reddit_helper import process_submission, write_submission, sleep
def main():
# configure API key
openai.api_key = config('OPENAI_API_KEY', default='')
brand_list = get_brands()
while True:
# Get the current timecode
timecode = get_timecode(datetime.now())
# Get the list of bots for the current timecode
bot_list = get_bots(timecode)
# Loop until the timecode changes
while get_timecode(datetime.now()) == timecode:
# Select a random bot and brand
bot = random.choice(bot_list)
reddit = login(bot)
if(not reddit):
print(f"Error: Could not login bot {bot.username}")
# Get brand
brand = random.choice(brand_list)
print(f"Brand: {brand.name}")
# Get a list of subreddits for the brand and select a random one
subreddit_list = get_sublist(brand)
# Get brand
subreddit = reddit.subreddit(random.choice(subreddit_list))
print(f"Subreddit: {subreddit.display_name}")
if bot.num_posts < HOURLY_POSTS:
# roll dice 0-9, if >=1, make post without brand
if random.randint(0, 9) == 0:
print(f"Making branded post. Post #{bot.num_posts + 1}")
write_submission(subreddit, brand)
else:
print(f"Making non-branded post. Post #{bot.num_posts + 1}")
write_submission(subreddit, None)
bot.num_posts += 1
if bot.num_comments < HOURLY_COMMENTS:
# Make a comment in the selected subreddit
print(f"Making comment. Comment #{bot.num_comments + 1}")
process_submission(subreddit, brand)
bot.num_comments += 1
time.sleep(sleep)
break # for debug only
if __name__ == "__main__":
main()