SMS Message Report

Generated: 2025-12-21 23:45
Source: sms.db
Total messages
42
Outgoing
17
Incoming
25
Date range
2025-12-20 → 2025-12-21
Date / Time Direction Text
2025-12-20 08:15:32 OUTGOING Hey, just checking in. Are we still on for 7pm?
2025-12-20 08:17:04 INCOMING Yes, absolutely. See you at the usual place.
2025-12-21 14:03:59 OUTGOING On my way now. Might be 5 minutes late.
2025-12-21 14:04:40 INCOMING No worries. I’m here already, take your time.

>>> Python Script Source

# read_sms_db.py

import sqlite3
import sys
from pathlib import Path

def main(db_path):
    db_path = Path(db_path)

    if not db_path.exists():
        print(f"[ERROR] File not found: {db_path}")
        return

    try:
        conn = sqlite3.connect(db_path)
    except sqlite3.Error as e:
        print(f"[ERROR] Could not connect to database: {e}")
        return

    cursor = conn.cursor()

    query = """
    SELECT
        datetime(date + strftime('%s','2001-01-01'), 'unixepoch', 'localtime') AS message_date,
        is_from_me,
        text
    FROM message
    ORDER BY date ASC
    LIMIT 100;
    """

    try:
        cursor.execute(query)
    except sqlite3.Error as e:
        print(f"[ERROR] Query failed: {e}")
        conn.close()
        return

    rows = cursor.fetchall()
    conn.close()

    if not rows:
        print("[INFO] No messages found.")
        return

    for msg_date, is_from_me, text in rows:
        direction = "OUTGOING" if is_from_me == 1 else "INCOMING"
        text = text if text is not None else ""
        print(f"[{msg_date}] {direction}: {text}")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python read_sms_db.py path/to/sms.db")
    else:
        main(sys.argv[1])