feat: начальный код
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def load_config() -> dict:
|
||||
dev_config = Path(__file__).parent.parent / "config.json"
|
||||
sys_config = Path("/etc/traffic-checker/config.json")
|
||||
|
||||
if dev_config.exists():
|
||||
config_path = dev_config
|
||||
elif sys_config.exists():
|
||||
config_path = sys_config
|
||||
else:
|
||||
raise FileNotFoundError(
|
||||
"Configuration file config.json not found in dev path or /etc/traffic-checker/"
|
||||
)
|
||||
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def fetch_server_data(server_uuid: str) -> dict:
|
||||
token = os.getenv("VIRTFUSION_TOKEN")
|
||||
|
||||
if not token:
|
||||
raise RuntimeError("VIRTFUSION_TOKEN environment variable is not set.")
|
||||
|
||||
url = f"https://virtfusion-nat.gullo.me/api/server/{server_uuid}"
|
||||
|
||||
headers = {
|
||||
"Accept": "application/json",
|
||||
"Authorization": f"Bearer {token}",
|
||||
}
|
||||
|
||||
params = {"state": "true"}
|
||||
|
||||
response = requests.get(url, headers=headers, params=params, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
return response.json()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = load_config()
|
||||
|
||||
for server in config["servers"]:
|
||||
data = fetch_server_data(server["uuid"])
|
||||
print(data)
|
||||
Reference in New Issue
Block a user