-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
74 lines (65 loc) · 2.51 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
66
67
68
69
70
71
72
73
74
import sys, logging
from args import *
from bot import RedditBot, GhostLogger
if __name__ == "__main__":
logger = GhostLogger
if "-v" in sys.argv or "--verbose" in sys.argv:
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
logger.addHandler(logging.StreamHandler())
logger.addHandler(logging.FileHandler('.log'))
formatter = logging.Formatter(
"\033[91m[ERROR!]\033[0m %(asctime)s \033[95m%(message)s\033[0m"
)
logger.handlers[0].setFormatter(formatter)
if len(sys.argv) == 1:
logger.error("No arguments provided. Use -h or --help for help.")
if "-v" not in sys.argv or "--verbose" not in sys.argv:
sys.exit("No arguments provided. Use -h or --help for help.")
sys.exit(1)
else:
args = cmdline_args()
if args["accounts"]:
try:
with open(args["accounts"], "r") as f:
accounts = f.readlines()
except FileNotFoundError:
logger.error(f"Accounts file not found: {args['accounts']}")
sys.exit(1)
else:
logger.error("No accounts file provided. Use -h or --help for help.")
sys.exit(1)
if args["links"]:
try:
with open(args["links"], "r") as f:
links = f.readlines()
except FileNotFoundError:
logger.error(f"Links file not found: {args['links']}")
sys.exit(1)
else:
logger.error("No links file provided. Use -h or --help for help.")
sys.exit(1)
bot = RedditBot(
verbose=args["verbose"]
)
for acc in accounts:
if acc not in ["\n", "\r\n"]:
username, password = acc.split("|")
try:
bot.login(username, password)
except AssertionError:
logger.error(f"Invalid account \033[4m{username}\033[0m")
continue
for entry in links:
contents = entry.strip("\n").split("|")
link = contents[0]
action = contents[1]
if action == "upvote":
bot.vote(link, True)
elif action == "downvote":
bot.vote(link, False)
elif action == "comment":
bot.comment(link, contents[2])
elif action in ["join", "leave"]:
bot.join_community(link, action == "join")
bot._dispose()