diff --git a/indexer/hasher.py b/indexer/hasher.py index 3770397..8c2ccc5 100644 --- a/indexer/hasher.py +++ b/indexer/hasher.py @@ -3,8 +3,8 @@ import ctypes from blake3 import blake3 # Windows atributy pro cloud/placeholder soubory -_FILE_ATTRIBUTE_OFFLINE = 0x00001000 -_FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x00040000 +_FILE_ATTRIBUTE_OFFLINE = 0x00001000 +_FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x00040000 _FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000 _CLOUD_MASK = _FILE_ATTRIBUTE_OFFLINE | _FILE_ATTRIBUTE_RECALL_ON_OPEN | _FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS diff --git a/main.py b/main.py index 06fa706..e5318af 100644 --- a/main.py +++ b/main.py @@ -180,6 +180,7 @@ def main(): "modified": len(modified_paths), "deleted": len(deleted_paths), "unchanged": len(unchanged_paths), + "skipped": len(skipped_files), } finalize_run(cur, run_id, stats) conn.commit() @@ -213,10 +214,14 @@ def main(): print("=" * 60) # ── 8. Generate Excel report ── + report_path = None try: from report import generate_report - report_dir = r"u:\Dropbox\!!!Days\Downloads Z230" + report_dir = r"z:\Dropbox\!!!Days\Downloads Z230" + for f in os.listdir(report_dir): + if f.endswith("DropboxBackupReport.xlsx"): + os.remove(os.path.join(report_dir, f)) timestamp = datetime.now().strftime("%Y-%m-%d %H_%M") report_path = os.path.join(report_dir, f"{timestamp} DropboxBackupReport.xlsx") print(f"\n[8] Generating report...") @@ -224,6 +229,52 @@ def main(): except Exception as e: print(f" WARN: Report generation failed: {e}") + # ── 9. Send email notification ── + try: + import sys + sys.path.insert(0, r"C:\Reporting\knihovny") + from EmailMessagingGraph import send_mail + + ts = datetime.now().strftime("%d.%m.%Y %H:%M") + changes = stats['new'] + stats['modified'] + stats['deleted'] + report_line = f"Report{report_path}" if report_path else "" + + skipped_row = "" + skipped_detail = "" + if skipped_files: + skipped_row = f"Preskocene{len(skipped_files):,}" + rows = "".join(f"{p}{r}" for p, r in skipped_files) + skipped_detail = f""" +

⚠ Preskocene soubory ({len(skipped_files)})

+ + + {rows} +
SouborDuvod
""" + + body = f""" + +

✓ Dropbox Ordinace Backup – {ts}

+ + + + + + + + + {skipped_row} + {report_line} +
Run #{run_id}
Celkem souboru{stats['total']:,}
Nove{stats['new']:,}
Zmenene{stats['modified']:,}
Smazane{stats['deleted']:,}
Nezmenene{stats['unchanged']:,}
Zmen celkem{changes:,}
+{skipped_detail} +

REPORTER • {ts}

+ +""" + subject = f"Dropbox Backup #{run_id} \u2013 {ts} ({changes} zmen)" + send_mail("vladimir.buzalka@buzalka.cz", subject, body, html=True) + print(f"\n[9] Email odeslan na vladimir.buzalka@buzalka.cz") + except Exception as e: + print(f" WARN: Email failed: {e}") + if __name__ == "__main__": main() diff --git a/report.py b/report.py index 84d59f2..f760a1e 100644 --- a/report.py +++ b/report.py @@ -77,7 +77,7 @@ def generate_report(output_path: str): cell.alignment = Alignment(horizontal="center") cell.border = thin_border - for row_idx, ev in enumerate(all_events, 2): + for row_idx, ev in enumerate(reversed(all_events), 2): run_id, started, event_type, rel_path, file_name, directory, old_size, new_size = ev size_change = "" @@ -115,7 +115,7 @@ def generate_report(output_path: str): if __name__ == "__main__": - REPORT_DIR = r"u:\Dropbox\!!!Days\Downloads Z230" + REPORT_DIR = r"z:\Dropbox\!!!Days\Downloads Z230" timestamp = dt.now().strftime("%Y-%m-%d %H_%M") default_name = f"{timestamp} DropboxBackupReport.xlsx" output = sys.argv[1] if len(sys.argv) > 1 else os.path.join(REPORT_DIR, default_name) diff --git a/run_backup.bat b/run_backup.bat new file mode 100644 index 0000000..6e9f5ed --- /dev/null +++ b/run_backup.bat @@ -0,0 +1,3 @@ +@echo off +cd /d C:\Reporting\DropboxBackup +C:\Reporting\Python\python.exe main.py