-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
73 lines (59 loc) · 2.09 KB
/
run.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
import praw
import configparser
import time
import pickledb
class C:
W, G, R, P, Y, C = '\033[0m', '\033[92m', '\033[91m', '\033[95m', '\033[93m', '\033[36m'
def main():
config = configparser.ConfigParser()
config.read('conf.ini')
reddit_user = config['REDDIT']['reddit_user']
reddit_pass = config['REDDIT']['reddit_pass']
client_id = config['REDDIT']['client_id']
client_secret = config['REDDIT']['client_secret']
target_subreddit = config['SETTINGS']['target_subreddit']
sleep_time = int(config['SETTINGS']['sleep_time'])
test_mode = config['SETTINGS'].getboolean('test_mode')
db = pickledb.load('users.db', False)
reddit = praw.Reddit(
username=reddit_user,
password=reddit_pass,
client_id=client_id,
client_secret=client_secret,
user_agent='Invite Bot (by u/impshum)'
)
tm = ''
if test_mode:
tm = f'{C.R}TEST MODE{C.Y}'
print(f"""{C.Y}
╦╔╗╔╦ ╦╦╔╦╗╔═╗ ╔╗ ╔═╗╔╦╗
║║║║╚╗╔╝║ ║ ║╣ ╠╩╗║ ║ ║ {tm}
╩╝╚╝ ╚╝ ╩ ╩ ╚═╝ ╚═╝╚═╝ ╩ {C.C}v1.0 {C.G}impshum{C.W}
""")
populate_db(db)
for user in db.getall():
approved = db.get(user)
now = time.strftime("%d/%m/%Y %H:%M:%S", time.gmtime(time.time()))
if not approved:
if not test_mode:
reddit.subreddit(target_subreddit).contributor.add(user)
db.set(user, 1)
db.dump()
print(f'{C.P}{now} {C.G}Approved {user}{C.W}')
if not test_mode:
time.sleep(sleep_time)
else:
print(f'{C.P}{now} {C.Y}Already Approved {user}{C.W}')
def populate_db(db):
with open('users.txt') as f:
users = f.readlines()
for user in users:
user = user.strip()
if not db.exists(user):
db.set(user, 0)
db.dump()
print(f'{C.P}{C.G}Added {user} to db{C.W}')
else:
print(f'{C.P}{C.Y}{user} exists in db{C.W}')
if __name__ == '__main__':
main()