import requests import json from datetime import datetime # Swagger JSON endpoint SWAGGER_URL = "https://api.kontur.io/layers/v2/swagger.json" # Имя выходного HTML-файла OUTPUT_FILE = "/var/www/html/wp-content/uploads/layers/layers.html" def fetch_layers(): response = requests.get(SWAGGER_URL) response.raise_for_status() swagger_data = response.json() # Извлекаем пути, фильтруем только те, что соответствуют /layers/ paths = swagger_data.get("paths", {}) layer_names = [] for path in paths: if path.startswith("/layers/") and path.count("/") == 2: layer_name = path.split("/")[-1] if layer_name not in layer_names: layer_names.append(layer_name) return sorted(layer_names) def generate_html(layers): now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") html_content = f""" Kontur Layers

Список слоев Kontur API

Обновлено: {now}

""" with open(OUTPUT_FILE, "w", encoding="utf-8") as f: f.write(html_content) print(f"[✓] Файл {OUTPUT_FILE} успешно создан.") def main(): try: layers = fetch_layers() generate_html(layers) except Exception as e: print(f"[Ошибка] Не удалось сгенерировать HTML: {e}") if __name__ == "__main__": main()