feat: 图片下载与数据目录本地化

- 新增 download_images.py: 批量下载消息图片到 downloads/images/
- 数据库移至 downloads/messages.db,SnifferStorage 默认使用项目目录
- 图片默认保存到 downloads/images/,支持 --out-dir 自定义
- .gitignore 排除 downloads/ 避免提交二进制文件
- 补充腾讯会议号过滤 prompt
- 补充 Obsidian 文档 is_read frontmatter
This commit is contained in:
Benature
2026-11-15 20:07:24 +08:00
parent cceeaf5c78
commit 81b6ff7a39
21 changed files with 2206 additions and 25 deletions

View File

@ -282,6 +282,23 @@ def cmd_summarize(args):
exclude_chat_ids=exclude_chat_ids,
include_outgoing=True,
)
from snooper_membership import MembershipError, filter_rows_with_membership
try:
rows, membership_stats = filter_rows_with_membership(
LarkClient(LarkAuth()), rows
)
except MembershipError as error:
raise SummaryError(
f"入群时间校验失败({error});已停止读取和总结。"
) from error
if membership_stats["excluded_chats"]:
print(
f"入群时间过滤: 排除未入群消息 "
f"{membership_stats['excluded_before_join']} 条,"
f"入群时间未知消息 {membership_stats['excluded_unknown']} 条,"
f"涉及 {membership_stats['excluded_chats']} 个群聊"
)
if args.dry_run:
records = [serialize_message(row, tz) for row in rows]
output_path = (
@ -297,9 +314,43 @@ def cmd_summarize(args):
f"({target_day.isoformat()},纳入消息 {len(rows)} 条,未发送给模型)"
)
return 0
if not getattr(args, "no_card_images", False):
from snooper_card_images import enrich_card_images
image_stats = enrich_card_images(
LarkClient(LarkAuth()), client, rows, max_images=3
)
if image_stats["candidates"]:
print(
f"卡片图片读取: 成功 {image_stats['enriched']} 张,"
f"失败/不可用 {image_stats['failed']} 张"
)
if not getattr(args, "no_videos", False):
from snooper_videos import enrich_videos
video_stats = enrich_videos(
LarkClient(LarkAuth()),
client,
rows,
max_frames=getattr(args, "video_frames", 12),
transcribe_audio=not getattr(args, "no_video_audio", False),
)
if video_stats["candidates"]:
print(
f"视频读取: 成功 {video_stats['enriched']} 个,"
f"失败/不可用 {video_stats['failed']} 个,"
f"新下载 {video_stats['downloaded']} 个,"
f"音轨转写 {video_stats['audio_transcribed']}/{video_stats['audio']},"
f"音轨失败 {video_stats['audio_failed']} 个"
)
previous_summary, previous_day_missing = load_previous_summary(
config["output"], target_day
)
from snooper_weekly import load_previous_weekly_background
previous_weekly_summary, previous_weekly_missing = (
load_previous_weekly_background(config["output"], target_day)
)
calendar_events = []
calendar_error = None
if not getattr(args, "no_calendar", False):
@ -346,6 +397,7 @@ def cmd_summarize(args):
calendar_events=calendar_events,
calendar_error=calendar_error,
self_name=self_name,
previous_weekly_summary=previous_weekly_summary,
)
output_path = (
args.output
@ -359,8 +411,13 @@ def cmd_summarize(args):
"model": model.rsplit("/", 1)[-1],
"is_read": False,
}
missing_background_tags = []
if previous_day_missing:
properties["tags"] = ["no_previous_day_log"]
missing_background_tags.append("no_previous_day_log")
if previous_weekly_missing:
missing_background_tags.append("no_previous_weekly")
if missing_background_tags:
properties["tags"] = missing_background_tags
content = add_obsidian_properties(content, properties)
output = write_summary(output_path, content)
dry_run_path = configured_output_path(
@ -390,12 +447,47 @@ def cmd_summarize(args):
return 1
def cmd_weekly(args):
from snooper_summary import SummaryError
from snooper_weekly import WeeklyError, generate_weekly
try:
generate_weekly(
week=args.week,
model=args.model or os.environ.get("MAGPIE_MODEL", "EFundGPT-dsv4-pro"),
base_url=args.base_url
or os.environ.get("MAGPIE_BASE_URL", "http://127.0.0.1:3425/v1"),
api_key=os.environ.get("MAGPIE_API_KEY"),
timeout=args.timeout,
config_path=args.config,
output=args.output,
overwrite=args.overwrite,
)
return 0
except (WeeklyError, SummaryError) as error:
print(f"周记生成失败: {error}", file=sys.stderr)
return 1
except OSError as error:
print(f"周记写入失败: {type(error).__name__}", file=sys.stderr)
return 1
def main():
parser = argparse.ArgumentParser(
prog="lark_snooper.py", description="LarkAgentX 历史同步与 EFundGPT 日度总结"
)
subparsers = parser.add_subparsers(dest="cmd", required=True)
weekly = subparsers.add_parser("weekly", help="根据日报生成周记并读取上周周记")
weekly.add_argument("--week", required=True, help="周内任意日期 YYYY-MM-DD")
weekly.add_argument("--model", help="实际模型段必须以 EFundGPT 开头")
weekly.add_argument("--base-url", help="Magpie OpenAI 兼容地址")
weekly.add_argument("--timeout", type=int, default=600)
weekly.add_argument("--config", help="YAML 配置路径;默认读取当前目录 config.yaml")
weekly.add_argument("-o", "--output", help="覆盖周记输出路径")
weekly.add_argument("--overwrite", action="store_true", help="覆盖已有周记")
weekly.set_defaults(fn=cmd_weekly)
web = subparsers.add_parser("web", help="打开本机会话搜索与忽略列表管理页")
web.add_argument("--port", type=int, default=8765, help="本机监听端口,默认 8765")
web.add_argument("--config", default="config.yaml", help="要维护的 YAML 配置路径")
@ -425,6 +517,10 @@ def main():
summarize.add_argument("--max-chars", type=int, default=80000, help="每个对话内每块消息最大字符数")
summarize.add_argument("--no-contacts", action="store_true", help="不联网获取相关会话通讯录")
summarize.add_argument("--no-calendar", action="store_true", help="不获取主日历日程")
summarize.add_argument("--no-card-images", action="store_true", help="不读取卡片图片")
summarize.add_argument("--no-videos", action="store_true", help="不下载或读取视频消息")
summarize.add_argument("--video-frames", type=int, default=12, help="每个视频最多抽帧数,默认 12;视频数量不设上限")
summarize.add_argument("--no-video-audio", action="store_true", help="不使用本地模型转写视频音轨")
summarize.add_argument("--no-fetch", action="store_true", help="只读取本地已入库记录")
summarize.add_argument("--force-fetch", action="store_true", help="即使本地已有数据也强制重新拉取")
summarize.add_argument("--config", help="YAML 配置路径;默认读取当前目录 config.yaml")