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.
This commit is contained in:
parent
3b7484fbe6
commit
f9fb7552bb
1 changed files with 8 additions and 22 deletions
30
monitor.py
30
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue