-
Notifications
You must be signed in to change notification settings - Fork 5
/
user_privacy_scrub.py
executable file
·48 lines (38 loc) · 1.36 KB
/
user_privacy_scrub.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
#!/usr/bin/env python3.6
#
# __main__.py
#
# statbot - Store Discord records for later analysis
# Copyright (c) 2017-2018 Ammon Smith
#
# statbot is available free of charge under the terms of the MIT
# License. You are free to redistribute and/or modify it under those
# terms. It is distributed in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY. See the LICENSE file for more details.
#
from collections import namedtuple
import logging
import sys
import yaml
import statbot
FakeUser = namedtuple('FakeUser', ('id', 'name'))
if __name__ == '__main__':
if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} config-file user-id")
exit(1)
with open(sys.argv[1], 'r') as fh:
config = yaml.safe_load(fh)
# Get arguments
db_url = config['bot']['db-url']
user_id = int(sys.argv[2])
# Set up logging
logger = logging.getLogger('statbot.script.user_privacy_scrub')
logger.setLevel(logging.INFO)
log_hndl = logging.StreamHandler(sys.stdout)
log_hndl.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
logger.addHandler(log_hndl)
# Open database connection
logger.info("Preparation done, starting user privacy scrub procedure...")
sql = statbot.sql.DiscordSqlHandler(db_url, None, logger)
sql.privacy_scrub(FakeUser(id=user_id, name=str(user_id)))
logger.info("Done! Exiting...")