#! /usr/bin/env python3 # WhatsApp Chat Archiver import sqlite3 import os import argparse import html from datetime import datetime, timedelta import shutil # WhatsApp's epoch starts on 2001-01-01 00:00:00 (Core Data timestamp) WHATSAPP_EPOCH = datetime(2001, 1, 1) def convert_whatsapp_timestamp(ts): """Converts WhatsApp's Core Data timestamp to a human-readable string.""" if not ts: return "" try: # Timestamps are seconds since the WhatsApp epoch dt = WHATSAPP_EPOCH + timedelta(seconds=ts) return dt.strftime('%Y-%m-%d %H:%M:%S') except (ValueError, TypeError): return "Invalid date" def get_media_tag(media_path, output_dir): """Generates the appropriate HTML tag for a given media file and copies it.""" if not media_path: return "" # Path in the DB is often relative like 'Media/WhatsApp Images/IMG-...' test_path = os.path.join(output_dir, 'Message', media_path) full_media_path = '' if not os.path.exists(test_path): return f'
Redirecting to WhatsApp Chats...
""") print(f"\nExport complete!") print(f"View your chats by opening either of these files in your browser:") print(f" • {os.path.abspath(index_path)}") print(f" • {os.path.abspath(redirect_index)}") if __name__ == "__main__": main()