-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaward_bot.py
executable file
·51 lines (39 loc) · 1.54 KB
/
award_bot.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
#!/usr/bin/env python3
"""Reddit AwardBot
Usage: award_bot.py <subreddit> [--dry] [--debug]
award_bot.py -h | --help
award_bot.py --version
Options:
--dry Run process and write to stdout (do not comment on Reddit)
--debug Enable HTTP debugging
-h, --help Show this screen
Environment Variables:
PRAW_SITE The name of the config section on praw.ini for this process
DATABASE_URL URI of the Postgres instance to use
"""
import os
from docopt import docopt, DocoptExit
from modules.awards import AwardBotProcess
from modules.shared.utils import setup_http_debugging
__version__ = '1.0.0'
if __name__ == '__main__':
# process commandline args
args = docopt(__doc__, version=f'Reddit AwardBot v{__version__}')
# check environment variables
database_url = os.getenv('DATABASE_URL')
if database_url is None:
raise DocoptExit("Missing DATABASE_URL variable.\n")
# we use uppercase for consistency but convert it to lowercase since that's what PRAW uses
praw_site = os.getenv('PRAW_SITE')
if praw_site is not None:
os.environ['praw_site'] = praw_site
praw_site = os.getenv('praw_site')
if praw_site is None:
raise DocoptExit("Missing PRAW_SITE variable.\n")
# run process
if args['--debug']:
setup_http_debugging()
subreddit = args['<subreddit>']
bot_process = AwardBotProcess(__version__, subreddit)
dry_run = args['--dry']
bot_process.run(dry_run)