Creating my own system because down with AI

This commit is contained in:
2025-08-29 21:03:06 +02:00
parent 90566154ec
commit ce811eae7e
2 changed files with 64 additions and 7 deletions

23
test.py
View File

@@ -7,43 +7,51 @@ from flask import Flask, jsonify
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Any
# Start background checker
import threading
# Disable warnings for self-signed certificates
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
services = [
"https://truenas.local/",
"https://example.com/",
"https://git.ihatemen.uk/"
"https://git.ihatemen.uk/",
]
services_status = {}
# Determine SSL verification based on hostname
def should_verify_ssl(url: str):
hostname = urlparse(url).hostname
return not (hostname and hostname.endswith(".local"))
# Function to check a single service
def check_service(url: str) -> tuple[str, dict[str, Any]]:
try:
start = time.time()
r = requests.head(url, allow_redirects=True, timeout=5, verify=should_verify_ssl(url))
r = requests.head(
url, allow_redirects=True, timeout=5, verify=should_verify_ssl(url)
)
latency = int((time.time() - start) * 1000)
return url, {
"status": "up" if r.ok else "down",
"latency": latency,
"error": None
"error": None,
}
except requests.exceptions.RequestException as e:
return url, {
"status": "down",
"latency": None,
"error": str(e),
"trace": traceback.format_exc()
"trace": traceback.format_exc(),
}
# Background thread that checks all services in parallel
def check_services_periodically(interval: int=5):
def check_services_periodically(interval: int = 5):
while True:
with ThreadPoolExecutor(max_workers=len(services)) as executor:
futures = [executor.submit(check_service, url) for url in services]
@@ -52,16 +60,17 @@ def check_services_periodically(interval: int=5):
services_status[url] = result
time.sleep(interval)
# Start background checker
import threading
threading.Thread(target=check_services_periodically, daemon=True).start()
# Flask app to serve status
app = Flask(__name__)
@app.route("/status")
def status():
return jsonify(services_status)
if __name__ == "__main__":
app.run(debug=True)

48
test2.py Normal file
View File

@@ -0,0 +1,48 @@
# import requests as r
from flask import jsonify, Flask
from typing import Any, Optional
class service:
url: str
status: Optional[int]
online: bool
private: bool
def __init__(self, url: str = "", private: bool = False):
self.url = url
self.private = private
self.online = False
self.status = None
def to_dict(self) -> dict[str, Any]:
return {
"url": self.url,
"status": self.status,
"private": self.private,
"online": self.online,
}
def set_status(self, status: int):
self.status = status
services: list[service] = [
service("https://git.ihatemen.uk"),
service("https://plex.ihatemen.uk"),
service("https://truenas.local", True),
]
# Flask app to serve status
app = Flask(__name__)
@app.route("/")
def status():
return jsonify([s.to_dict() for s in services])
# Only run if directly running file
if __name__ == "__main__":
app.run(debug=True)