blog/monitor.py
Yax f9fb7552bb 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.
2026-01-10 16:36:44 +01:00

44 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import requests
import time
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv(".env")
# Configuration from environment
stacosys_url = os.getenv("STACOSYS_URL", "")
external_check_cmd = os.getenv("EXTERNAL_CHECK", "")
def get_comment_count():
"""Fetch the total number of comments from Stacosys API.
Returns:
int: Total comment count, or 0 if request fails
"""
req_url = stacosys_url + "/comments/count"
resp = requests.get(url=req_url)
return 0 if not resp.ok else int(resp.json()["count"])
def _exit_program():
"""Exit the program with status code 0."""
sys.exit(0)
initial_count = get_comment_count()
print(f"Comments = {initial_count}")
while True:
# check number of comments every 60 seconds
for _ in range(15):
time.sleep(60)
if initial_count != get_comment_count():
_exit_program()
# check if git repo changed every 15 minutes
if external_check_cmd and os.system(external_check_cmd):
_exit_program()