Compare commits
2 Commits
3e68e96c8a
...
7d5d3dc0c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d5d3dc0c8 | |||
| 8167a3ffff |
@@ -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.
|
||||
|
||||
92
Scripts/python/check_file_age.py
Normal file
92
Scripts/python/check_file_age.py
Normal file
@@ -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 <mappa_utvonal> <max_perc>
|
||||
|
||||
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 <mappa> <perc>"}))
|
||||
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)
|
||||
92
Scripts/python/check_file_age_de.py
Normal file
92
Scripts/python/check_file_age_de.py
Normal file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Skript zur Überprüfung des Dateialters für n8n-Automatisierung.
|
||||
Verwendung: python3 check_file_age_de.py <verzeichnispfad> <max_minuten>
|
||||
|
||||
Ausgabe: JSON-Format (n8n-freundlich)
|
||||
Exit-Code: 0 (wenn alles ok), 1 (wenn eine alte Datei gefunden wurde oder ein Fehler auftrat)
|
||||
"""
|
||||
|
||||
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 = []
|
||||
|
||||
# Überprüfung, ob das Verzeichnis existiert
|
||||
if not os.path.exists(directory):
|
||||
return {
|
||||
"status": "error",
|
||||
"alert": True,
|
||||
"message": f"Das angegebene Verzeichnis existiert nicht: {directory}",
|
||||
"files": []
|
||||
}
|
||||
|
||||
try:
|
||||
# Dateien auflisten
|
||||
files_in_dir = os.listdir(directory)
|
||||
|
||||
for filename in files_in_dir:
|
||||
filepath = os.path.join(directory, filename)
|
||||
|
||||
# Nur Dateien prüfen (keine Verzeichnisse)
|
||||
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"{len(too_old_files)} Datei(en) gefunden, die älter als {max_age_minutes} Minuten sind!",
|
||||
"directory": directory,
|
||||
"limit_minutes": max_age_minutes,
|
||||
"files": too_old_files
|
||||
}
|
||||
|
||||
return {
|
||||
"status": "ok",
|
||||
"alert": False,
|
||||
"message": "Alle Dateien sind aktuell.",
|
||||
"directory": directory,
|
||||
"files": []
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"alert": True,
|
||||
"message": f"Fehler während der Überprüfung aufgetreten: {str(e)}",
|
||||
"files": []
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Parameter aus der Befehlszeile übernehmen
|
||||
if len(sys.argv) < 2:
|
||||
print(json.dumps({"status": "error", "message": "Fehlender Parameter! Verwendung: python3 check_file_age_de.py <verzeichnis> <minuten>"}))
|
||||
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-Ausgabe für n8n
|
||||
print(json.dumps(result, indent=2))
|
||||
|
||||
# Exit-Code für den n8n SSH-Node festlegen
|
||||
if result.get("alert"):
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(0)
|
||||
70
Scripts/python/md_to_pdf_recursive.py
Normal file
70
Scripts/python/md_to_pdf_recursive.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user