A CLI tool to query local WeChat data with 11 commands: sessions, history, search, contacts, members, stats, export, favorites, unread, new-messages, and init. Features: - Self-contained init with key extraction (no external deps) - On-the-fly SQLCipher decryption with caching - JSON output by default for LLM/AI tool integration - Message type filtering and chat statistics - Markdown/txt export for conversations - Cross-platform: macOS, Windows, Linux
30 lines
709 B
Python
30 lines
709 B
Python
"""输出格式化 — JSON (大模型友好) / Text (人类可读)"""
|
|
|
|
import json
|
|
import sys
|
|
|
|
|
|
def output_json(data, file=None):
|
|
file = file or sys.stdout
|
|
json.dump(data, file, ensure_ascii=False, indent=2)
|
|
file.write('\n')
|
|
|
|
|
|
def output_text(text, file=None):
|
|
file = file or sys.stdout
|
|
file.write(text)
|
|
if not text.endswith('\n'):
|
|
file.write('\n')
|
|
|
|
|
|
def output(data, fmt='json', file=None):
|
|
if fmt == 'json':
|
|
output_json(data, file)
|
|
else:
|
|
if isinstance(data, str):
|
|
output_text(data, file)
|
|
elif isinstance(data, dict) and 'text' in data:
|
|
output_text(data['text'], file)
|
|
else:
|
|
output_json(data, file)
|