fixes
This commit is contained in:
@@ -14,5 +14,5 @@ RUN pip install --no-cache-dir praw
|
|||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
# Run the script
|
# Always generate config.py from environment before starting
|
||||||
CMD ["python", "Bot/main.py"]
|
CMD ["/bin/sh", "-c", "python populate_config.py && python Bot/main.py"]
|
||||||
|
|||||||
52
populate_config.py
Normal file
52
populate_config.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
CONFIG_KEYS = [
|
||||||
|
"client_id",
|
||||||
|
"client_secret",
|
||||||
|
"user_agent",
|
||||||
|
"username",
|
||||||
|
"password",
|
||||||
|
"sub_name",
|
||||||
|
"max_days",
|
||||||
|
"max_posts",
|
||||||
|
"sleep_minutes",
|
||||||
|
]
|
||||||
|
|
||||||
|
DEFAULTS = {
|
||||||
|
"client_id": "",
|
||||||
|
"client_secret": "",
|
||||||
|
"user_agent": "",
|
||||||
|
"username": "",
|
||||||
|
"password": "",
|
||||||
|
"sub_name": "",
|
||||||
|
"max_days": 180,
|
||||||
|
"max_posts": 180,
|
||||||
|
"sleep_minutes": 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try both plain and DP_ prefix for env vars
|
||||||
|
config = {}
|
||||||
|
for key in CONFIG_KEYS:
|
||||||
|
env_val = os.getenv(key.upper())
|
||||||
|
if env_val is None:
|
||||||
|
env_val = os.getenv(f"DP_{key.upper()}")
|
||||||
|
if env_val is not None:
|
||||||
|
# Cast numeric values
|
||||||
|
if key in ["max_days", "max_posts", "sleep_minutes"]:
|
||||||
|
try:
|
||||||
|
config[key] = int(env_val)
|
||||||
|
except ValueError:
|
||||||
|
config[key] = DEFAULTS[key]
|
||||||
|
else:
|
||||||
|
config[key] = env_val
|
||||||
|
else:
|
||||||
|
config[key] = DEFAULTS[key]
|
||||||
|
|
||||||
|
# Write config.py
|
||||||
|
with open("config/config.py", "w", encoding="utf-8") as f:
|
||||||
|
f.write('"""\nConfiguration for the DeletedPosts bot.\n"""\n\n')
|
||||||
|
f.write('config = ' + json.dumps(config, indent=4) + '\n')
|
||||||
|
f.write('\nTEMPLATE = f"""# configuration for DeletedPosts bot\n# edit the values of the dictionary below and restart the bot\n\nconfig = {config!r}\n"""\n')
|
||||||
|
|
||||||
|
print("config/config.py has been populated from environment variables.")
|
||||||
Reference in New Issue
Block a user