From f9fb7552bb5ab1aeef16e617c4f182e7a870fbf3 Mon Sep 17 00:00:00 2001 From: Yax Date: Sat, 10 Jan 2026 16:36:08 +0100 Subject: [PATCH] Update monitor.py to use .env instead of params.json Complete the migration started in 42c89dc by updating the monitoring script to load configuration from .env files using python-dotenv. --- monitor.py | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/monitor.py b/monitor.py index bad2367..fe7a018 100755 --- a/monitor.py +++ b/monitor.py @@ -5,13 +5,14 @@ import sys import os import requests import time -import json +from dotenv import load_dotenv +# Load environment variables from .env file +load_dotenv(".env") -def fread(filename): - """Read file and close the file.""" - with open(filename, "r") as f: - return f.read() +# Configuration from environment +stacosys_url = os.getenv("STACOSYS_URL", "") +external_check_cmd = os.getenv("EXTERNAL_CHECK", "") def get_comment_count(): @@ -20,11 +21,8 @@ def get_comment_count(): Returns: int: Total comment count, or 0 if request fails """ - req_url = params["stacosys_url"] + "/comments/count" - query_params = dict( - token=params["stacosys_token"] - ) - resp = requests.get(url=req_url, params=query_params) + req_url = stacosys_url + "/comments/count" + resp = requests.get(url=req_url) return 0 if not resp.ok else int(resp.json()["count"]) @@ -33,18 +31,6 @@ def _exit_program(): sys.exit(0) -# Default parameters. -params = { - "stacosys_token": "", - "stacosys_url": "", - "external_check": "", -} - -# If params.json exists, load it. -if os.path.isfile("params.json"): - params.update(json.loads(fread("params.json"))) - -external_check_cmd = params["external_check"] initial_count = get_comment_count() print(f"Comments = {initial_count}") while True: