Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Search, analyze, and interact with Xiaohongshu (RedNote/小红书) content via a local MCP server and shell scripts.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
tools/xhs-downloader/export_memory.py
1#!/usr/bin/env python2"""3从 XHS-Downloader 数据库导出笔记到单个 Markdown 文件45用法:6python export_memory.py [db_path] [output_file]78默认:9db_path: Volume/Download/ExploreData.db10output_file: xhs_memory.md11"""12import sqlite313import sys14from pathlib import Path15from datetime import datetime161718def export_memory(db_path: Path = None, output_file: Path = None):19db_path = db_path or Path("Volume/Download/ExploreData.db")20output_file = output_file or Path("xhs_memory.md")2122if not db_path.exists():23print(f"错误: 数据库不存在: {db_path}")24return False2526conn = sqlite3.connect(db_path)27cursor = conn.cursor()2829# 查询所有作品30cursor.execute("""31SELECT 作品标题, 发布时间, 作品链接, 作品描述, 作者昵称, 作品标签32FROM explore_data33ORDER BY 发布时间 DESC34""")3536rows = cursor.fetchall()37conn.close()3839if not rows:40print("数据库为空")41return False4243# 生成 Markdown44output = f"# 小红书收藏/点赞笔记 Memory\n\n"45output += f"> 导出时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"46output += f"> 共 {len(rows)} 条笔记\n\n---\n\n"4748for i, (title, time, link, desc, author, tags) in enumerate(rows, 1):49output += f"## {i}. {title or '无标题'}\n\n"50output += f"- **作者**: {author or '未知'}\n"51output += f"- **时间**: {time or '未知'}\n"52output += f"- **链接**: {link or '无'}\n"53if tags:54output += f"- **标签**: {tags}\n"55output += f"\n### 内容\n\n{desc or '无内容'}\n\n---\n\n"5657# 保存文件58output_file.write_text(output, encoding="utf-8")59print(f"导出完成: {output_file.absolute()}")60print(f"共 {len(rows)} 条笔记")61return True626364if __name__ == "__main__":65db_path = Path(sys.argv[1]) if len(sys.argv) > 1 else None66output_file = Path(sys.argv[2]) if len(sys.argv) > 2 else None67export_memory(db_path, output_file)68