From 8167a3ffffacca44a9c20d93251340ce5030e283 Mon Sep 17 00:00:00 2001 From: wpanda Date: Wed, 25 Mar 2026 11:34:33 +0100 Subject: [PATCH] neue script, check file age --- GEMINI.md | 7 +- Scripts/python/check_file_age.py | 92 +++++++++++++++++++++++++++ Scripts/python/md_to_pdf_recursive.py | 70 ++++++++++++++++++++ 3 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 Scripts/python/check_file_age.py create mode 100644 Scripts/python/md_to_pdf_recursive.py diff --git a/GEMINI.md b/GEMINI.md index 425debd..5f5b656 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -34,6 +34,7 @@ A kedvenc programozási nyelvem a Python. Weboldalak amiket hasznälni szoktunk: mermaid.live -Általában fedora linux alatt dolgozunk. -Második leggyakrabban használt linux az Ubuntu alapu. -Virtualizácionk Proxmox VE +Általában szerver oldalon Fedora Linux alatt dolgozunk. +A második leggyakrabban használt linux az Ubuntu alapú (szintén szerver). +Kliens oldalon (munkaállomás) Windows 11-et vagy macOS-t használunk. +Virtualizációnk Proxmox VE. diff --git a/Scripts/python/check_file_age.py b/Scripts/python/check_file_age.py new file mode 100644 index 0000000..4354a70 --- /dev/null +++ b/Scripts/python/check_file_age.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +""" +Fájl kor ellenőrző script n8n automatizáláshoz. +Használat: python3 check_file_age.py + +Kimenet: JSON formátum (n8n barát) +Exit kód: 0 (ha minden rendben), 1 (ha régi fájlt talált vagy hiba történt) +""" + +import os +import time +import sys +import json + +def check_files(directory, max_age_minutes=40): + now = time.time() + max_age_seconds = max_age_minutes * 60 + too_old_files = [] + + # Mappa létezésének ellenőrzése + if not os.path.exists(directory): + return { + "status": "error", + "alert": True, + "message": f"A megadott könyvtár nem létezik: {directory}", + "files": [] + } + + try: + # Fájlok listázása + files_in_dir = os.listdir(directory) + + for filename in files_in_dir: + filepath = os.path.join(directory, filename) + + # Csak a fájlokat ellenőrizzük (mappákat nem) + if os.path.isfile(filepath): + file_age_seconds = now - os.path.getmtime(filepath) + + if file_age_seconds > max_age_seconds: + age_min = round(file_age_seconds / 60, 1) + too_old_files.append({ + "file": filename, + "age_minutes": age_min, + "last_modified": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(os.path.getmtime(filepath))) + }) + + if too_old_files: + return { + "status": "alert", + "alert": True, + "message": f"Találtam {len(too_old_files)} db fájlt, ami régebbi mint {max_age_minutes} perc!", + "directory": directory, + "limit_minutes": max_age_minutes, + "files": too_old_files + } + + return { + "status": "ok", + "alert": False, + "message": "Minden fájl friss.", + "directory": directory, + "files": [] + } + + except Exception as e: + return { + "status": "error", + "alert": True, + "message": f"Hiba történt az ellenőrzés közben: {str(e)}", + "files": [] + } + +if __name__ == "__main__": + # Paraméterek átvétele a parancssorból + if len(sys.argv) < 2: + print(json.dumps({"status": "error", "message": "Hiányzó paraméter! Használat: python3 check_file_age.py "})) + sys.exit(1) + + dir_to_check = sys.argv[1] + age_limit = int(sys.argv[2]) if len(sys.argv) > 2 else 40 + + result = check_files(dir_to_check, age_limit) + + # JSON kimenet az n8n számára + print(json.dumps(result, indent=2)) + + # Exit code beállítása az n8n SSH Node számára + if result.get("alert"): + sys.exit(1) + else: + sys.exit(0) diff --git a/Scripts/python/md_to_pdf_recursive.py b/Scripts/python/md_to_pdf_recursive.py new file mode 100644 index 0000000..29d09fa --- /dev/null +++ b/Scripts/python/md_to_pdf_recursive.py @@ -0,0 +1,70 @@ +""" +Használati útmutató / Usage: + +1. Telepítés / Installation: + pip install markdown-pdf + +2. Futtatás / Execution: + - Aktuális könyvtár bejárása: + python Scripts/python/md_to_pdf_recursive.py + - Konkrét könyvtár megadása: + python Scripts/python/md_to_pdf_recursive.py Dev/APS-SFTP01 + +A script rekurzívan végigjárja a megadott könyvtárat, és minden .md fájl mellé +létrehoz egy azonos nevű .pdf fájlt. A .git, .venv és __pycache__ könyvtárakat kihagyja. +""" + +import os +import sys +from markdown_pdf import Section, MarkdownPdf + +def convert_md_to_pdf(root_dir): + """ + Rekurzívan végigjárja a megadott könyvtárat és minden .md fájlból PDF-et készít. + """ + print(f"Keresés indítása a következő könyvtárban: {root_dir}") + + # Kizárandó könyvtárak (pl. git, virtuális környezet) + exclude_dirs = {'.git', '.venv', '__pycache__', 'node_modules'} + + count = 0 + for root, dirs, files in os.walk(root_dir): + # Alkönyvtárak szűrése (helyben módosítva a dirs listát) + dirs[:] = [d for d in dirs if d not in exclude_dirs] + + for file in files: + if file.endswith(".md"): + md_path = os.path.join(root, file) + pdf_path = os.path.splitext(md_path)[0] + ".pdf" + + print(f"Konvertálás: {md_path} -> {pdf_path}") + + try: + # Markdown olvasása + with open(md_path, "r", encoding="utf-8") as f: + md_content = f.read() + + # PDF generálása + pdf = MarkdownPdf(toc_level=2) + pdf.add_section(Section(md_content, toc=False)) + pdf.save(pdf_path) + + count += 1 + except Exception as e: + print(f"Hiba a fájl feldolgozása közben ({md_path}): {e}") + + print(f"\nKész! Összesen {count} fájl lett konvertálva.") + +if __name__ == "__main__": + # Ha nincs megadva útvonal, az aktuális könyvtárat használja + target_path = sys.argv[1] if len(sys.argv) > 1 else "." + + # Ellenőrizzük a függőséget + try: + import markdown_pdf + except ImportError: + print("Hiba: A 'markdown-pdf' könyvtár nincs telepítve.") + print("Telepítés: pip install markdown-pdf") + sys.exit(1) + + convert_md_to_pdf(target_path)