notebook
This commit is contained in:
@@ -42,6 +42,17 @@ from pathlib import Path
|
||||
SCRIPTS_DIR = Path("/scripts")
|
||||
LOGS_DIR = SCRIPTS_DIR # vse do /scripts/
|
||||
|
||||
# --- Auto-install dependencies ---
|
||||
_REQ_FILE = SCRIPTS_DIR / "requirements.txt"
|
||||
if _REQ_FILE.exists():
|
||||
_ret = subprocess.run(
|
||||
[sys.executable, "-m", "pip", "install", "-q", "-r", str(_REQ_FILE)],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
if _ret.returncode != 0:
|
||||
print(f"[WARN] pip install selhal:\n{_ret.stderr.strip()}")
|
||||
# ---------------------------------
|
||||
|
||||
# Definice pipeline (step_id, label, executable filename)
|
||||
STEPS = [
|
||||
("1b", "Graph delta sync", "1b_parse_emails_graph_delta_v1.0.py"),
|
||||
@@ -165,9 +176,77 @@ def main() -> int:
|
||||
print(f" Konec: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f" Per-krok logy: {LOGS_DIR}/pipeline_<id>.log")
|
||||
|
||||
_send_report(results, failed, total_dur)
|
||||
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
def _send_report(results: list, failed: int, total_dur: float) -> None:
|
||||
try:
|
||||
import importlib.util, sys as _sys
|
||||
_lib = SCRIPTS_DIR / "EmailMessagingGraph.py"
|
||||
spec = importlib.util.spec_from_file_location("EmailMessagingGraph", _lib)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
except Exception as e:
|
||||
print(f"[report] Nelze nacist EmailMessagingGraph: {e}")
|
||||
return
|
||||
|
||||
ok_icon = "✅"
|
||||
err_icon = "❌"
|
||||
overall = ok_icon if failed == 0 else err_icon
|
||||
|
||||
rows = ""
|
||||
for sid, label, ret, dur in results:
|
||||
icon = ok_icon if ret == 0 else err_icon
|
||||
color = "#d4edda" if ret == 0 else "#f8d7da"
|
||||
status = "OK" if ret == 0 else f"FAIL ({ret})"
|
||||
rows += (
|
||||
f"<tr style='background:{color}'>"
|
||||
f"<td style='padding:4px 10px'>{icon} {label}</td>"
|
||||
f"<td style='padding:4px 10px;text-align:center'>{status}</td>"
|
||||
f"<td style='padding:4px 10px;text-align:right'>{fmt_dur(dur)}</td>"
|
||||
f"</tr>"
|
||||
)
|
||||
|
||||
body = f"""
|
||||
<html><body style="font-family:sans-serif;font-size:14px">
|
||||
<p>{overall} <b>Email pipeline</b> — {datetime.now().strftime('%Y-%m-%d %H:%M')}
|
||||
| celkem {fmt_dur(total_dur)}
|
||||
| {len(results)} kroků, {failed} chyb</p>
|
||||
<table border="0" cellspacing="1" cellpadding="0" style="border-collapse:collapse">
|
||||
<tr style="background:#343a40;color:white">
|
||||
<th style="padding:4px 10px;text-align:left">Krok</th>
|
||||
<th style="padding:4px 10px">Status</th>
|
||||
<th style="padding:4px 10px;text-align:right">Čas</th>
|
||||
</tr>
|
||||
{rows}
|
||||
</table>
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
# Attach logs of failed steps
|
||||
attachments = []
|
||||
for sid, label, ret, dur in results:
|
||||
if ret != 0:
|
||||
log_path = LOGS_DIR / f"pipeline_{sid}.log"
|
||||
if log_path.exists() and log_path.stat().st_size > 0:
|
||||
attachments.append(log_path)
|
||||
|
||||
subject = f"{overall} Email pipeline — {datetime.now().strftime('%Y-%m-%d %H:%M')}"
|
||||
try:
|
||||
mod.send_mail(
|
||||
"vladimir.buzalka@buzalka.cz",
|
||||
subject,
|
||||
body,
|
||||
html=True,
|
||||
attachments=attachments or None,
|
||||
)
|
||||
print(f"[report] Email odeslan na vladimir.buzalka@buzalka.cz")
|
||||
except Exception as e:
|
||||
print(f"[report] Chyba pri odesilani: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
raise SystemExit(main())
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
msal
|
||||
requests
|
||||
pymongo
|
||||
python-dateutil
|
||||
extract-msg
|
||||
cryptography
|
||||
asn1crypto
|
||||
beautifulsoup4
|
||||
oletools
|
||||
msoffcrypto-tool
|
||||
olefile
|
||||
RTFDE
|
||||
compressed-rtf
|
||||
lark
|
||||
pcodedmp
|
||||
tzlocal
|
||||
six
|
||||
psycopg
|
||||
Reference in New Issue
Block a user