2026-02-23 23:31:15 +00:00
|
|
|
"""
|
|
|
|
|
Configuration for the DeletedPosts bot.
|
|
|
|
|
|
|
|
|
|
This module exposes a single dictionary called ``config`` which holds all
|
|
|
|
|
of the parameters required to connect to Reddit and control the behaviour of
|
2026-02-24 21:45:13 +00:00
|
|
|
the bot. When you first run the program the file will be created for you
|
2026-02-23 23:31:15 +00:00
|
|
|
with empty values; you should edit it before starting the bot. You can also
|
|
|
|
|
reset the file to defaults by running the application with the
|
|
|
|
|
``reset_config`` command-line argument.
|
|
|
|
|
|
|
|
|
|
Example usage::
|
|
|
|
|
|
|
|
|
|
from config import config
|
|
|
|
|
print(config['client_id'])
|
|
|
|
|
"""
|
|
|
|
|
|
2026-02-24 21:45:13 +00:00
|
|
|
import os
|
|
|
|
|
|
2026-02-23 23:31:15 +00:00
|
|
|
config = {
|
|
|
|
|
"client_id": "",
|
|
|
|
|
"client_secret": "",
|
|
|
|
|
"user_agent": "",
|
|
|
|
|
"username": "",
|
|
|
|
|
"password": "",
|
|
|
|
|
"sub_name": "",
|
|
|
|
|
# numeric settings are stored as integers here rather than strings
|
|
|
|
|
"max_days": 180,
|
|
|
|
|
"max_posts": 180,
|
|
|
|
|
"sleep_minutes": 5,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 21:45:13 +00:00
|
|
|
# allow container/WC users to override values via environment variables
|
|
|
|
|
# variables are expected to be UPPERCASE versions of the keys (or prefixed
|
|
|
|
|
# with DP_). Numeric values will be converted to ints automatically.
|
|
|
|
|
for key in list(config):
|
|
|
|
|
# check both bare and prefixed variants
|
|
|
|
|
env_names = [key.upper(), f"DP_{key.upper()}"]
|
|
|
|
|
for env in env_names:
|
|
|
|
|
val = os.getenv(env)
|
|
|
|
|
if val is not None:
|
|
|
|
|
# cast numeric entries back to int when appropriate
|
|
|
|
|
if isinstance(config[key], int):
|
|
|
|
|
try:
|
|
|
|
|
config[key] = int(val)
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass # leave original if conversion fails
|
|
|
|
|
else:
|
|
|
|
|
config[key] = val
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
2026-02-23 23:31:15 +00:00
|
|
|
# same data as a text template. both ``main.py`` and ``utils.actions`` import
|
|
|
|
|
# this so that the file can be created or reset without duplicating the
|
|
|
|
|
# literal configuration body.
|
|
|
|
|
TEMPLATE = f"""# configuration for DeletedPosts bot
|
|
|
|
|
# edit the values of the dictionary below and restart the bot
|
|
|
|
|
|
|
|
|
|
config = {config!r}
|
|
|
|
|
"""
|