-
Notifications
You must be signed in to change notification settings - Fork 46
/
modLogParser.py
66 lines (53 loc) · 1.78 KB
/
modLogParser.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
#!/usr/bin/python3
import praw
import os
import logging.handlers
import sys
import configparser
USER_AGENT = "Mod Log Parser (by /u/Watchful1)"
LOG_LEVEL = logging.INFO
SUBREDDIT = "CompetitiveOverwatch"
INFRACTIONS_LIMIT = 3
DAYS_OLD_TO_CLEAR = 30
REMOVAL_REASON = "douchebaggary/slur"
LOG_FOLDER_NAME = "logs"
if not os.path.exists(LOG_FOLDER_NAME):
os.makedirs(LOG_FOLDER_NAME)
LOG_FILENAME = LOG_FOLDER_NAME+"/"+"bot.log"
LOG_FILE_BACKUPCOUNT = 5
LOG_FILE_MAXSIZE = 1024 * 1024 * 16
log = logging.getLogger("bot")
log.setLevel(LOG_LEVEL)
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s')
log_stderrHandler = logging.StreamHandler()
log_stderrHandler.setFormatter(log_formatter)
log.addHandler(log_stderrHandler)
if LOG_FILENAME is not None:
log_fileHandler = logging.handlers.RotatingFileHandler(LOG_FILENAME,
maxBytes=LOG_FILE_MAXSIZE,
backupCount=LOG_FILE_BACKUPCOUNT)
log_fileHandler.setFormatter(log_formatter)
log.addHandler(log_fileHandler)
user = None
if len(sys.argv) >= 2:
user = sys.argv[1]
else:
log.error("No user specified, aborting")
sys.exit(0)
try:
r = praw.Reddit(
user
,user_agent=USER_AGENT)
except configparser.NoSectionError:
log.error(f"User {user} not in praw.ini, aborting")
sys.exit(0)
removed_ids = []
for log_object in r.subreddit(SUBREDDIT).mod.log(action="removelink", limit=10000):
removed_ids.append(log_object.target_fullname)
log.info(f"Found {len(removed_ids)} removed posts")
removed_clip_ids = []
for post in r.info(removed_ids):
if post.domain == "clips.twitch.tv":
log.info(f"https://old.reddit.com{post.permalink}")
removed_clip_ids.append(post.name)
log.info(f"Found {len(removed_clip_ids)} removed clips")