'''
Check if the main loop is running
/usr/bin/python3 /var/www/moduleair_pro_4g/tests/check_running.py
'''
import psutil
import json

def is_script_running(script_name):
    """Check if a given Python script is currently running."""
    for process in psutil.process_iter(['pid', 'cmdline']):
        if process.info['cmdline'] and script_name in " ".join(process.info['cmdline']):
            return True  # Script is running
    return False  # Script is not running

script_to_check = "/var/www/moduleair_pro_4g/loop/SARA_send_data_v2.py" 

# Determine script status
is_running = is_script_running(script_to_check)

# Create JSON response
response = {
    "message": "The script is still running.❌❌❌" if is_running else "The script is NOT running.✅✅✅",
    "running": is_running
}

# Print JSON output
print(json.dumps(response, indent=4))  # Pretty print for readability
