weflow-cli 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +105 -0
- package/CHANGELOG.md +121 -0
- package/CONTRIBUTING.md +45 -0
- package/LICENSE +21 -21
- package/OPERATIONS.md +272 -0
- package/README.en.md +281 -0
- package/README.md +334 -149
- package/SECURITY.md +47 -0
- package/bin/weflow-cli.ts +4050 -581
- package/dist/bin/weflow-cli.js +4310 -588
- package/dist/bin/weflow-cli.js.map +1 -1
- package/dist/mcp-server/index.js +178 -236
- package/dist/mcp-server/index.js.map +1 -1
- package/dist/src/core/dbPathService.d.ts +15 -1
- package/dist/src/core/dbPathService.d.ts.map +1 -1
- package/dist/src/core/dbPathService.js +177 -19
- package/dist/src/core/dbPathService.js.map +1 -1
- package/dist/src/core/keyService.d.ts +8 -0
- package/dist/src/core/keyService.d.ts.map +1 -1
- package/dist/src/core/keyService.js +127 -22
- package/dist/src/core/keyService.js.map +1 -1
- package/dist/src/core/ntCore.d.ts +59 -1
- package/dist/src/core/ntCore.d.ts.map +1 -1
- package/dist/src/core/ntCore.js +201 -65
- package/dist/src/core/ntCore.js.map +1 -1
- package/dist/src/core/sqlcipherCore.d.ts.map +1 -1
- package/dist/src/core/sqlcipherCore.js +18 -1
- package/dist/src/core/sqlcipherCore.js.map +1 -1
- package/dist/src/core/wcdbCore.d.ts.map +1 -1
- package/dist/src/core/wcdbCore.js +3 -6
- package/dist/src/core/wcdbCore.js.map +1 -1
- package/dist/src/services/assistantDaemon.d.ts +19 -0
- package/dist/src/services/assistantDaemon.d.ts.map +1 -0
- package/dist/src/services/assistantDaemon.js +117 -0
- package/dist/src/services/assistantDaemon.js.map +1 -0
- package/dist/src/services/assistantMemory.d.ts +36 -0
- package/dist/src/services/assistantMemory.d.ts.map +1 -0
- package/dist/src/services/assistantMemory.js +182 -0
- package/dist/src/services/assistantMemory.js.map +1 -0
- package/dist/src/services/assistantPrivacy.d.ts +25 -0
- package/dist/src/services/assistantPrivacy.d.ts.map +1 -0
- package/dist/src/services/assistantPrivacy.js +77 -0
- package/dist/src/services/assistantPrivacy.js.map +1 -0
- package/dist/src/services/assistantRouting.d.ts +18 -0
- package/dist/src/services/assistantRouting.d.ts.map +1 -0
- package/dist/src/services/assistantRouting.js +68 -0
- package/dist/src/services/assistantRouting.js.map +1 -0
- package/dist/src/services/assistantService.d.ts +37 -0
- package/dist/src/services/assistantService.d.ts.map +1 -0
- package/dist/src/services/assistantService.js +284 -0
- package/dist/src/services/assistantService.js.map +1 -0
- package/dist/src/services/assistantTools.d.ts +24 -0
- package/dist/src/services/assistantTools.d.ts.map +1 -0
- package/dist/src/services/assistantTools.js +582 -0
- package/dist/src/services/assistantTools.js.map +1 -0
- package/dist/src/services/chatService.d.ts +44 -0
- package/dist/src/services/chatService.d.ts.map +1 -1
- package/dist/src/services/chatService.js +105 -4
- package/dist/src/services/chatService.js.map +1 -1
- package/dist/src/services/configService.d.ts +55 -0
- package/dist/src/services/configService.d.ts.map +1 -1
- package/dist/src/services/configService.js +147 -6
- package/dist/src/services/configService.js.map +1 -1
- package/dist/src/services/evidenceService.d.ts +30 -0
- package/dist/src/services/evidenceService.d.ts.map +1 -0
- package/dist/src/services/evidenceService.js +98 -0
- package/dist/src/services/evidenceService.js.map +1 -0
- package/dist/src/services/exportService.d.ts +13 -20
- package/dist/src/services/exportService.d.ts.map +1 -1
- package/dist/src/services/exportService.js +113 -47
- package/dist/src/services/exportService.js.map +1 -1
- package/dist/src/services/initKeyService.d.ts +19 -0
- package/dist/src/services/initKeyService.d.ts.map +1 -0
- package/dist/src/services/initKeyService.js +80 -0
- package/dist/src/services/initKeyService.js.map +1 -0
- package/dist/src/services/messageContract.d.ts +23 -0
- package/dist/src/services/messageContract.d.ts.map +1 -0
- package/dist/src/services/messageContract.js +49 -0
- package/dist/src/services/messageContract.js.map +1 -0
- package/dist/src/services/messageQuery.d.ts +7 -0
- package/dist/src/services/messageQuery.d.ts.map +1 -0
- package/dist/src/services/messageQuery.js +30 -0
- package/dist/src/services/messageQuery.js.map +1 -0
- package/dist/src/services/wechat-formatter.js +14 -14
- package/dist/src/services/wechatMessageService.d.ts.map +1 -1
- package/dist/src/services/wechatMessageService.js +31 -3
- package/dist/src/services/wechatMessageService.js.map +1 -1
- package/dist/src/services/whitelistService.d.ts +52 -4
- package/dist/src/services/whitelistService.d.ts.map +1 -1
- package/dist/src/services/whitelistService.js +183 -17
- package/dist/src/services/whitelistService.js.map +1 -1
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/dateRange.d.ts +15 -0
- package/dist/src/utils/dateRange.d.ts.map +1 -0
- package/dist/src/utils/dateRange.js +48 -0
- package/dist/src/utils/dateRange.js.map +1 -0
- package/dist/src/utils/mcpSecurity.d.ts +5 -0
- package/dist/src/utils/mcpSecurity.d.ts.map +1 -0
- package/dist/src/utils/mcpSecurity.js +39 -0
- package/dist/src/utils/mcpSecurity.js.map +1 -0
- package/dist/src/utils/packageRoot.d.ts +2 -0
- package/dist/src/utils/packageRoot.d.ts.map +1 -0
- package/dist/src/utils/packageRoot.js +16 -0
- package/dist/src/utils/packageRoot.js.map +1 -0
- package/dist/src/utils/python.d.ts +2 -0
- package/dist/src/utils/python.d.ts.map +1 -0
- package/dist/src/utils/python.js +72 -0
- package/dist/src/utils/python.js.map +1 -0
- package/dist/src/utils/pythonProcessEnv.d.ts +3 -0
- package/dist/src/utils/pythonProcessEnv.d.ts.map +1 -0
- package/dist/src/utils/pythonProcessEnv.js +46 -0
- package/dist/src/utils/pythonProcessEnv.js.map +1 -0
- package/dist/src/utils/talkerUtils.d.ts +4 -1
- package/dist/src/utils/talkerUtils.d.ts.map +1 -1
- package/dist/src/utils/talkerUtils.js +9 -9
- package/dist/src/utils/talkerUtils.js.map +1 -1
- package/dist/src/utils/wechatEmoji.d.ts +5 -0
- package/dist/src/utils/wechatEmoji.d.ts.map +1 -0
- package/dist/src/utils/wechatEmoji.js +35 -0
- package/dist/src/utils/wechatEmoji.js.map +1 -0
- package/docs/AI_INTERFACE.md +189 -0
- package/docs/BRANCHES.md +87 -0
- package/docs/DATA_CONTRACT.md +74 -0
- package/docs/DECISIONS.md +270 -0
- package/docs/DEEPSEEK_V4_FLASH/346/226/275/345/267/245/346/226/207/346/241/243.md +234 -0
- package/docs/EVIDENCE_GUIDE.md +96 -0
- package/docs/MCP.md +95 -0
- package/docs/PARTNERS.md +41 -0
- package/docs/PROJECT_STATE.md +96 -0
- package/docs/RELEASING.md +124 -0
- package/docs/ROADMAP.md +191 -0
- package/docs/SETUP.md +103 -0
- package/docs/images/weflow-architecture-gpt-image-2.png +0 -0
- package/docs/images/weflow-architecture.png +0 -0
- package/docs/images/weflow-architecture.svg +65 -0
- package/mcp-server/index.ts +169 -269
- package/package.json +81 -72
- package/requirements-3x.txt +4 -0
- package/requirements-voice.txt +15 -0
- package/requirements.txt +9 -0
- package/resources/js/marked.min.js +69 -0
- package/resources/wechat-emoji/666.png +0 -0
- package/resources/wechat-emoji/Awesome.png +0 -0
- package/resources/wechat-emoji/Concerned.png +0 -0
- package/resources/wechat-emoji/Cry.png +0 -0
- package/resources/wechat-emoji/Emm.png +0 -0
- package/resources/wechat-emoji/Facepalm.png +0 -0
- package/resources/wechat-emoji/Grin.png +0 -0
- package/resources/wechat-emoji/OK.png +0 -0
- package/resources/wechat-emoji/Respect.png +0 -0
- package/resources/wechat-emoji/Sick.png +0 -0
- package/resources/wechat-emoji/Sleep.png +0 -0
- package/resources/wechat-emoji/Smile.png +0 -0
- package/resources/wechat-emoji//344/272/262/344/272/262.png +0 -0
- package/resources/wechat-emoji//344/276/277/344/276/277.png +0 -0
- package/resources/wechat-emoji//345/201/267/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/202/262/346/205/242.png +0 -0
- package/resources/wechat-emoji//345/206/215/350/247/201.png +0 -0
- package/resources/wechat-emoji//345/207/213/350/260/242.png +0 -0
- package/resources/wechat-emoji//345/212/240/346/262/271.png +0 -0
- package/resources/wechat-emoji//345/213/276/345/274/225.png +0 -0
- package/resources/wechat-emoji//345/217/221/345/221/206.png +0 -0
- package/resources/wechat-emoji//345/217/221/346/200/222.png +0 -0
- package/resources/wechat-emoji//345/217/221/346/212/226.png +0 -0
- package/resources/wechat-emoji//345/217/257/346/200/234.png +0 -0
- package/resources/wechat-emoji//345/217/263/345/223/274/345/223/274.png +0 -0
- package/resources/wechat-emoji//345/217/271/346/260/224.png +0 -0
- package/resources/wechat-emoji//345/220/203/347/223/234.png +0 -0
- package/resources/wechat-emoji//345/220/210/345/215/201.png +0 -0
- package/resources/wechat-emoji//345/220/220.png +0 -0
- package/resources/wechat-emoji//345/221/262/347/211/231.png +0 -0
- package/resources/wechat-emoji//345/222/222/351/252/202.png +0 -0
- package/resources/wechat-emoji//345/222/226/345/225/241.png +0 -0
- package/resources/wechat-emoji//345/223/207.png +0 -0
- package/resources/wechat-emoji//345/225/244/351/205/222.png +0 -0
- package/resources/wechat-emoji//345/230/230.png +0 -0
- package/resources/wechat-emoji//345/230/264/345/224/207.png +0 -0
- package/resources/wechat-emoji//345/230/277/345/223/210.png +0 -0
- package/resources/wechat-emoji//345/233/247.png +0 -0
- package/resources/wechat-emoji//345/233/260.png +0 -0
- package/resources/wechat-emoji//345/235/217/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/244/247/345/223/255.png +0 -0
- package/resources/wechat-emoji//345/244/251/345/225/212.png +0 -0
- package/resources/wechat-emoji//345/244/252/351/230/263.png +0 -0
- package/resources/wechat-emoji//345/244/261/346/234/233.png +0 -0
- package/resources/wechat-emoji//345/245/270/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/245/275/347/232/204.png +0 -0
- package/resources/wechat-emoji//345/247/224/345/261/210.png +0 -0
- package/resources/wechat-emoji//345/256/263/347/276/236.png +0 -0
- package/resources/wechat-emoji//345/260/264/345/260/254.png +0 -0
- package/resources/wechat-emoji//345/272/206/347/245/235.png +0 -0
- package/resources/wechat-emoji//345/274/261.png +0 -0
- package/resources/wechat-emoji//345/274/272.png +0 -0
- package/resources/wechat-emoji//345/276/227/346/204/217.png +0 -0
- package/resources/wechat-emoji//345/276/256/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/277/203/347/242/216.png +0 -0
- package/resources/wechat-emoji//345/277/253/345/223/255/344/272/206.png +0 -0
- package/resources/wechat-emoji//346/201/220/346/203/247.png +0 -0
- package/resources/wechat-emoji//346/202/240/351/227/262.png +0 -0
- package/resources/wechat-emoji//346/203/212/346/201/220.png +0 -0
- package/resources/wechat-emoji//346/203/212/350/256/266.png +0 -0
- package/resources/wechat-emoji//346/204/211/345/277/253.png +0 -0
- package/resources/wechat-emoji//346/206/250/347/254/221.png +0 -0
- package/resources/wechat-emoji//346/211/223/350/204/270.png +0 -0
- package/resources/wechat-emoji//346/212/223/347/213/202.png +0 -0
- package/resources/wechat-emoji//346/212/240/351/274/273.png +0 -0
- package/resources/wechat-emoji//346/212/261/346/213/263.png +0 -0
- package/resources/wechat-emoji//346/213/245/346/212/261.png +0 -0
- package/resources/wechat-emoji//346/213/263/345/244/264.png +0 -0
- package/resources/wechat-emoji//346/215/202/350/204/270.png +0 -0
- package/resources/wechat-emoji//346/217/241/346/211/213.png +0 -0
- package/resources/wechat-emoji//346/222/207/345/230/264.png +0 -0
- package/resources/wechat-emoji//346/223/246/346/261/227.png +0 -0
- package/resources/wechat-emoji//346/225/262/346/211/223.png +0 -0
- package/resources/wechat-emoji//346/227/240/350/257/255.png +0 -0
- package/resources/wechat-emoji//346/227/272/346/237/264.png +0 -0
- package/resources/wechat-emoji//346/231/225.png +0 -0
- package/resources/wechat-emoji//346/234/210/344/272/256.png +0 -0
- package/resources/wechat-emoji//346/234/272/346/231/272.png +0 -0
- package/resources/wechat-emoji//346/261/227.png +0 -0
- package/resources/wechat-emoji//346/265/201/346/263/252.png +0 -0
- package/resources/wechat-emoji//347/202/270/345/274/271.png +0 -0
- package/resources/wechat-emoji//347/203/237/350/212/261.png +0 -0
- package/resources/wechat-emoji//347/210/206/347/253/271.png +0 -0
- package/resources/wechat-emoji//347/210/261/345/277/203.png +0 -0
- package/resources/wechat-emoji//347/214/252/345/244/264.png +0 -0
- package/resources/wechat-emoji//347/216/253/347/221/260.png +0 -0
- package/resources/wechat-emoji//347/224/237/347/227/205.png +0 -0
- package/resources/wechat-emoji//347/226/221/351/227/256.png +0 -0
- package/resources/wechat-emoji//347/231/274.png +0 -0
- package/resources/wechat-emoji//347/231/275/347/234/274.png +0 -0
- package/resources/wechat-emoji//347/232/261/347/234/211.png +0 -0
- package/resources/wechat-emoji//347/235/241.png +0 -0
- package/resources/wechat-emoji//347/240/264/346/266/225/344/270/272/347/254/221.png +0 -0
- package/resources/wechat-emoji//347/244/274/347/211/251.png +0 -0
- package/resources/wechat-emoji//347/244/276/344/274/232/347/244/276/344/274/232.png +0 -0
- package/resources/wechat-emoji//347/246/217.png +0 -0
- package/resources/wechat-emoji//347/254/221/350/204/270.png +0 -0
- package/resources/wechat-emoji//347/272/242/345/214/205.png +0 -0
- package/resources/wechat-emoji//347/277/273/347/231/275/347/234/274.png +0 -0
- package/resources/wechat-emoji//350/200/266.png +0 -0
- package/resources/wechat-emoji//350/203/234/345/210/251.png +0 -0
- package/resources/wechat-emoji//350/204/270/347/272/242.png +0 -0
- package/resources/wechat-emoji//350/211/262.png +0 -0
- package/resources/wechat-emoji//350/213/246/346/266/251.png +0 -0
- package/resources/wechat-emoji//350/217/234/345/210/200.png +0 -0
- package/resources/wechat-emoji//350/233/213/347/263/225.png +0 -0
- package/resources/wechat-emoji//350/241/260.png +0 -0
- package/resources/wechat-emoji//350/243/202/345/274/200.png +0 -0
- package/resources/wechat-emoji//350/256/251/346/210/221/347/234/213/347/234/213.png +0 -0
- package/resources/wechat-emoji//350/260/203/347/232/256.png +0 -0
- package/resources/wechat-emoji//350/267/263/350/267/263.png +0 -0
- package/resources/wechat-emoji//350/275/254/345/234/210.png +0 -0
- package/resources/wechat-emoji//351/204/231/350/247/206.png +0 -0
- package/resources/wechat-emoji//351/227/255/345/230/264.png +0 -0
- package/resources/wechat-emoji//351/230/264/351/231/251.png +0 -0
- package/resources/wechat-emoji//351/232/276/350/277/207.png +0 -0
- package/resources/wechat-emoji//351/252/267/351/253/205.png +0 -0
- package/resources/wechat-emoji//351/274/223/346/216/214.png +0 -0
- package/scripts/_batch_link_sources.py +73 -73
- package/scripts/_utils.py +29 -0
- package/scripts/annual_report.py +796 -796
- package/scripts/auto_tag.py +128 -128
- package/scripts/biz_daily.py +210 -53
- package/scripts/chat_report.py +10 -0
- package/scripts/chat_stats.py +702 -702
- package/scripts/classify_daily.py +17 -11
- package/scripts/create_reading_notes.py +370 -370
- package/scripts/daily_stats.py +132 -0
- package/scripts/enrich_backlinks.py +163 -163
- package/scripts/export_chat_html.py +1704 -107
- package/scripts/extract_todos.py +445 -404
- package/scripts/fav_server.py +119 -12
- package/scripts/fix_topics.py +111 -111
- package/scripts/generate_ai_report.py +1 -1
- package/scripts/generate_html.py +597 -277
- package/scripts/inspection_records.py +354 -0
- package/scripts/mcp_bridge.py +398 -398
- package/scripts/nt_decrypt.py +702 -48
- package/scripts/pipeline.py +27 -19
- package/scripts/promote_all.py +312 -310
- package/scripts/promote_ideas.py +299 -297
- package/scripts/rag_chat.py +194 -191
- package/scripts/semantic_search.py +435 -431
- package/scripts/sync_fav.py +201 -146
- package/scripts/sync_weread.py +192 -192
- package/scripts/vault_rag.py +140 -139
- package/scripts/vault_search.py +141 -141
- package/scripts/wechat_emoji.py +132 -0
- package/scripts/wechat_emoticon.py +433 -0
- package/scripts/wechat_image.py +258 -0
- package/scripts/wechat_voice.py +327 -0
- package/src/core/dbPathService.ts +163 -18
- package/src/core/keyService.ts +137 -25
- package/src/core/ntCore.ts +215 -62
- package/src/core/sqlcipherCore.ts +17 -1
- package/src/core/wcdbCore.ts +3 -7
- package/src/services/assistantDaemon.ts +111 -0
- package/src/services/assistantMemory.ts +193 -0
- package/src/services/assistantPrivacy.ts +87 -0
- package/src/services/assistantRouting.ts +92 -0
- package/src/services/assistantService.ts +295 -0
- package/src/services/assistantTools.ts +549 -0
- package/src/services/chatService.ts +133 -4
- package/src/services/configService.ts +194 -6
- package/src/services/evidenceService.ts +129 -0
- package/src/services/exportService.ts +113 -48
- package/src/services/initKeyService.ts +83 -0
- package/src/services/messageContract.ts +77 -0
- package/src/services/messageQuery.ts +38 -0
- package/src/services/wechat-formatter.ts +348 -348
- package/src/services/wechatMessageService.ts +25 -3
- package/src/services/wereadService.ts +308 -308
- package/src/services/whitelistService.ts +209 -22
- package/src/types.ts +20 -0
- package/src/utils/dateRange.ts +58 -0
- package/src/utils/mcpSecurity.ts +39 -0
- package/src/utils/packageRoot.ts +14 -0
- package/src/utils/python.ts +73 -0
- package/src/utils/pythonProcessEnv.ts +45 -0
- package/src/utils/talkerUtils.ts +14 -2
- package/dist/src/utils/errors.d.ts +0 -25
- package/dist/src/utils/errors.d.ts.map +0 -1
- package/dist/src/utils/errors.js +0 -43
- package/dist/src/utils/errors.js.map +0 -1
- package/dist/src/utils/pythonRunner.d.ts +0 -27
- package/dist/src/utils/pythonRunner.d.ts.map +0 -1
- package/dist/src/utils/pythonRunner.js +0 -62
- package/dist/src/utils/pythonRunner.js.map +0 -1
- package/src/utils/errors.ts +0 -42
- package/src/utils/pythonRunner.ts +0 -81
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""公众号推送频率与日报处理频率统计。"""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from collections import defaultdict
|
|
10
|
+
from datetime import datetime, timedelta, timezone
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
14
|
+
from _utils import decrypt_lock, load_config
|
|
15
|
+
from biz_daily import extract_article_info, get_db_keys
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
from sqlcipher3 import dbapi2 as sqlcipher
|
|
19
|
+
except ImportError:
|
|
20
|
+
print('请安装 sqlcipher3: pip install sqlcipher3', file=sys.stderr)
|
|
21
|
+
sys.exit(1)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def load_processed_counts(start_date: str, end_date: str) -> dict[str, int]:
|
|
25
|
+
root = Path(__file__).resolve().parent.parent / 'output' / 'biz-daily'
|
|
26
|
+
counts: dict[str, int] = defaultdict(int)
|
|
27
|
+
current = datetime.strptime(start_date, '%Y-%m-%d').date()
|
|
28
|
+
end = datetime.strptime(end_date, '%Y-%m-%d').date()
|
|
29
|
+
while current <= end:
|
|
30
|
+
path = root / current.isoformat() / '.articles.json'
|
|
31
|
+
if path.exists():
|
|
32
|
+
try:
|
|
33
|
+
payload = json.loads(path.read_text(encoding='utf-8'))
|
|
34
|
+
for article in payload.get('articles', []):
|
|
35
|
+
source = str(article.get('source') or '').strip()
|
|
36
|
+
if source:
|
|
37
|
+
counts[source] += 1
|
|
38
|
+
except (OSError, ValueError, TypeError):
|
|
39
|
+
pass
|
|
40
|
+
current += timedelta(days=1)
|
|
41
|
+
return dict(counts)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main() -> None:
|
|
45
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
46
|
+
parser = argparse.ArgumentParser(description='统计公众号推送与日报处理频率')
|
|
47
|
+
parser.add_argument('--days', type=int, default=30, help='统计最近多少天,默认 30')
|
|
48
|
+
parser.add_argument('--limit', type=int, default=30, help='最多显示多少个公众号,默认 30')
|
|
49
|
+
parser.add_argument('--json', action='store_true', help='输出 JSON')
|
|
50
|
+
args = parser.parse_args()
|
|
51
|
+
if args.days < 1 or args.days > 3650:
|
|
52
|
+
parser.error('--days 必须在 1 到 3650 之间')
|
|
53
|
+
if args.limit < 1:
|
|
54
|
+
parser.error('--limit 必须大于 0')
|
|
55
|
+
|
|
56
|
+
tz = timezone(timedelta(hours=8))
|
|
57
|
+
today = datetime.now(tz).date()
|
|
58
|
+
start_date = today - timedelta(days=args.days - 1)
|
|
59
|
+
start_ts = int(datetime.combine(start_date, datetime.min.time(), tzinfo=tz).timestamp())
|
|
60
|
+
end_ts = int(datetime.combine(today + timedelta(days=1), datetime.min.time(), tzinfo=tz).timestamp())
|
|
61
|
+
|
|
62
|
+
config = load_config()
|
|
63
|
+
keys = get_db_keys(config)
|
|
64
|
+
conn = sqlcipher.connect(keys['biz_db'])
|
|
65
|
+
conn.execute(f'PRAGMA key = "x\'{keys["biz_key"]}{keys["biz_salt"]}\'";')
|
|
66
|
+
cursor = conn.cursor()
|
|
67
|
+
|
|
68
|
+
name_map: dict[str, str] = {}
|
|
69
|
+
if keys['contact_key'] and os.path.exists(keys['contact_db']):
|
|
70
|
+
try:
|
|
71
|
+
contact = sqlcipher.connect(keys['contact_db'])
|
|
72
|
+
contact.execute(f'PRAGMA key = "x\'{keys["contact_key"]}{keys["contact_salt"]}\'";')
|
|
73
|
+
name_map = dict(contact.execute(
|
|
74
|
+
"SELECT username, COALESCE(NULLIF(remark,''), NULLIF(nick_name,''), username) "
|
|
75
|
+
"FROM contact WHERE username LIKE 'gh_%'"
|
|
76
|
+
).fetchall())
|
|
77
|
+
contact.close()
|
|
78
|
+
except Exception:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
rows: list[dict] = []
|
|
82
|
+
users = [row[0] for row in cursor.execute(
|
|
83
|
+
"SELECT user_name FROM Name2Id WHERE user_name LIKE 'gh_%'"
|
|
84
|
+
).fetchall()]
|
|
85
|
+
for user in users:
|
|
86
|
+
table = 'Msg_' + hashlib.md5(user.encode()).hexdigest()
|
|
87
|
+
try:
|
|
88
|
+
records = cursor.execute(
|
|
89
|
+
f'SELECT create_time, message_content FROM "{table}" '
|
|
90
|
+
'WHERE create_time >= ? AND create_time < ? ORDER BY create_time',
|
|
91
|
+
(start_ts, end_ts),
|
|
92
|
+
).fetchall()
|
|
93
|
+
except Exception:
|
|
94
|
+
continue
|
|
95
|
+
article_count = sum(
|
|
96
|
+
1 for _, content in records
|
|
97
|
+
if content and extract_article_info(content).get('title')
|
|
98
|
+
)
|
|
99
|
+
if article_count:
|
|
100
|
+
rows.append({'name': str(name_map.get(user, user)), 'id': user, 'pushed': article_count})
|
|
101
|
+
conn.close()
|
|
102
|
+
|
|
103
|
+
processed = load_processed_counts(start_date.isoformat(), today.isoformat())
|
|
104
|
+
for row in rows:
|
|
105
|
+
row['processed'] = processed.get(row['name'], 0)
|
|
106
|
+
rows.sort(key=lambda row: (-row['processed'], -row['pushed'], row['name']))
|
|
107
|
+
|
|
108
|
+
if args.json:
|
|
109
|
+
json_output = {
|
|
110
|
+
'success': True,
|
|
111
|
+
'period': {
|
|
112
|
+
'start': start_date.isoformat(),
|
|
113
|
+
'end': today.isoformat(),
|
|
114
|
+
'days': args.days,
|
|
115
|
+
},
|
|
116
|
+
'totalSources': len(rows),
|
|
117
|
+
'sources': rows[:args.limit],
|
|
118
|
+
}
|
|
119
|
+
print(json.dumps(json_output, ensure_ascii=False, indent=2))
|
|
120
|
+
return
|
|
121
|
+
|
|
122
|
+
print(f'公众号频率统计({start_date.isoformat()} 至 {today.isoformat()})')
|
|
123
|
+
print('说明:推送数是数据库中的文章数;处理数是已生成日报的文章数,不等同于打开次数。')
|
|
124
|
+
print(f'共统计 {len(rows)} 个有推送记录的公众号\n')
|
|
125
|
+
print(f'{"排名":<5}{"公众号":<28}{"推送数":>8}{"处理数":>8}{"ID"}')
|
|
126
|
+
print('-' * 72)
|
|
127
|
+
for index, row in enumerate(rows[:args.limit], 1):
|
|
128
|
+
print(f'{index:<5}{row["name"][:26]:<28}{row["pushed"]:>8}{row["processed"]:>8} {row["id"]}')
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == '__main__':
|
|
132
|
+
main()
|
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
双向链接增强 — 为文章添加同主题、共享概念的相关文章链接。
|
|
4
|
-
|
|
5
|
-
用法:
|
|
6
|
-
python scripts/enrich_backlinks.py --date 2026-05-22
|
|
7
|
-
python scripts/enrich_backlinks.py --date 2026-05-22 --dry-run
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import sys, os, re
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
from collections import defaultdict
|
|
13
|
-
|
|
14
|
-
from _utils import parse_frontmatter
|
|
15
|
-
|
|
16
|
-
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
17
|
-
PROJECT_ROOT = os.path.dirname(SCRIPTS_DIR)
|
|
18
|
-
DEFAULT_SOURCE = os.path.join(PROJECT_ROOT, 'output', 'biz-daily')
|
|
19
|
-
|
|
20
|
-
TOPIC_ORDER = ['AI', '学术', '新闻', '文学', '投资']
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def collect_articles(date_dir: str) -> list[dict]:
|
|
24
|
-
"""收集目录下所有文章,提取元数据。"""
|
|
25
|
-
articles = []
|
|
26
|
-
for topic in TOPIC_ORDER:
|
|
27
|
-
topic_dir = Path(date_dir) / topic
|
|
28
|
-
if not topic_dir.is_dir():
|
|
29
|
-
continue
|
|
30
|
-
for md_file in sorted(topic_dir.glob('*.md')):
|
|
31
|
-
try:
|
|
32
|
-
content = md_file.read_text(encoding='utf-8')
|
|
33
|
-
except Exception:
|
|
34
|
-
continue
|
|
35
|
-
fm, body = parse_frontmatter(content)
|
|
36
|
-
# 检查是否已经有相关阅读段落
|
|
37
|
-
if '## 相关阅读' in body:
|
|
38
|
-
continue # 已处理,跳过
|
|
39
|
-
|
|
40
|
-
articles.append({
|
|
41
|
-
'path': md_file,
|
|
42
|
-
'topic': topic,
|
|
43
|
-
'filename': f'{topic}/{md_file.name}',
|
|
44
|
-
'title': fm.get('title', md_file.stem),
|
|
45
|
-
'source': fm.get('source', ''),
|
|
46
|
-
'tags': fm.get('tags', []),
|
|
47
|
-
'concepts': fm.get('concepts', fm.get('wikilinks', [])),
|
|
48
|
-
'relevance': fm.get('relevance', ''),
|
|
49
|
-
})
|
|
50
|
-
return articles
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def find_related(article: dict, all_articles: list[dict]) -> list[dict]:
|
|
54
|
-
"""查找与给定文章相关的文章。"""
|
|
55
|
-
# 同主题文章(排除自身)
|
|
56
|
-
same_topic = [a for a in all_articles
|
|
57
|
-
if a['topic'] == article['topic']
|
|
58
|
-
and a['filename'] != article['filename']]
|
|
59
|
-
|
|
60
|
-
# 共享概念的文章
|
|
61
|
-
my_concepts = set(article['concepts']) if isinstance(article['concepts'], list) else set()
|
|
62
|
-
shared_concept = []
|
|
63
|
-
if my_concepts:
|
|
64
|
-
shared_concept = [a for a in all_articles
|
|
65
|
-
if a['filename'] != article['filename']
|
|
66
|
-
and a['topic'] != article['topic']
|
|
67
|
-
and set(a['concepts'] if isinstance(a['concepts'], list) else []) & my_concepts]
|
|
68
|
-
|
|
69
|
-
# 优先:同主题 + 高相关 + 共享概念
|
|
70
|
-
related = []
|
|
71
|
-
seen = set()
|
|
72
|
-
|
|
73
|
-
# 先加同主题高相关
|
|
74
|
-
for a in same_topic:
|
|
75
|
-
if a['relevance'] == '高':
|
|
76
|
-
related.append(a)
|
|
77
|
-
seen.add(a['filename'])
|
|
78
|
-
|
|
79
|
-
# 共享概念
|
|
80
|
-
for a in shared_concept:
|
|
81
|
-
if a['filename'] not in seen:
|
|
82
|
-
related.append(a)
|
|
83
|
-
seen.add(a['filename'])
|
|
84
|
-
|
|
85
|
-
# 补充同主题中相关
|
|
86
|
-
for a in same_topic:
|
|
87
|
-
if a['filename'] not in seen and a['relevance'] == '中':
|
|
88
|
-
related.append(a)
|
|
89
|
-
seen.add(a['filename'])
|
|
90
|
-
|
|
91
|
-
# 最后补任意来源
|
|
92
|
-
for a in same_topic:
|
|
93
|
-
if a['filename'] not in seen:
|
|
94
|
-
related.append(a)
|
|
95
|
-
seen.add(a['filename'])
|
|
96
|
-
|
|
97
|
-
return related[:5]
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def enrich_article(article: dict, related: list[dict], dry_run=False):
|
|
101
|
-
"""为文章末尾追加相关阅读段落。"""
|
|
102
|
-
if not related:
|
|
103
|
-
return 0
|
|
104
|
-
|
|
105
|
-
lines = ['', '---', '', '## 相关阅读', '']
|
|
106
|
-
for a in related:
|
|
107
|
-
label = f"📎 {a['title']}"
|
|
108
|
-
if a.get('source'):
|
|
109
|
-
label += f" — {a['source']}"
|
|
110
|
-
# 使用相对路径 Wikilink
|
|
111
|
-
link_path = a['filename'].replace('/', '/')
|
|
112
|
-
lines.append(f'- [[{link_path}|{label}]]')
|
|
113
|
-
|
|
114
|
-
appendix = '\n'.join(lines) + '\n'
|
|
115
|
-
|
|
116
|
-
if dry_run:
|
|
117
|
-
print(f' → {article["title"][:40]}')
|
|
118
|
-
print(f' 相关: {", ".join(a["title"][:30] for a in related)}')
|
|
119
|
-
return len(related)
|
|
120
|
-
|
|
121
|
-
filepath = article['path']
|
|
122
|
-
current = filepath.read_text(encoding='utf-8')
|
|
123
|
-
filepath.write_text(current.rstrip() + '\n' + appendix, encoding='utf-8')
|
|
124
|
-
return len(related)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def main():
|
|
128
|
-
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
129
|
-
import argparse
|
|
130
|
-
parser = argparse.ArgumentParser(description='为文章添加双向链接(相关阅读)')
|
|
131
|
-
parser.add_argument('--date', required=True, help='日期 YYYY-MM-DD')
|
|
132
|
-
parser.add_argument('--dry-run', action='store_true', help='仅预览不写入')
|
|
133
|
-
parser.add_argument('--source', default=DEFAULT_SOURCE, help='源目录')
|
|
134
|
-
args = parser.parse_args()
|
|
135
|
-
|
|
136
|
-
date_dir = os.path.join(args.source, args.date)
|
|
137
|
-
if not os.path.isdir(date_dir):
|
|
138
|
-
print(f'[ERROR] 目录不存在: {date_dir}')
|
|
139
|
-
sys.exit(1)
|
|
140
|
-
|
|
141
|
-
articles = collect_articles(date_dir)
|
|
142
|
-
print(f'找到 {len(articles)} 篇文章')
|
|
143
|
-
print(f'主题分布: {dict((t, len([a for a in articles if a["topic"]==t])) for t in TOPIC_ORDER if any(a["topic"]==t for a in articles))}')
|
|
144
|
-
print()
|
|
145
|
-
|
|
146
|
-
enriched = 0
|
|
147
|
-
skipped = 0
|
|
148
|
-
for article in articles:
|
|
149
|
-
related = find_related(article, articles)
|
|
150
|
-
if not related:
|
|
151
|
-
skipped += 1
|
|
152
|
-
continue
|
|
153
|
-
n = enrich_article(article, related, args.dry_run)
|
|
154
|
-
if n > 0:
|
|
155
|
-
enriched += 1
|
|
156
|
-
|
|
157
|
-
print(f'\n✓ 完成: {enriched} 篇已增强, {skipped} 篇无关联文章')
|
|
158
|
-
if args.dry_run:
|
|
159
|
-
print(' (--dry-run 模式,未实际写入)')
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if __name__ == '__main__':
|
|
163
|
-
main()
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
双向链接增强 — 为文章添加同主题、共享概念的相关文章链接。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
python scripts/enrich_backlinks.py --date 2026-05-22
|
|
7
|
+
python scripts/enrich_backlinks.py --date 2026-05-22 --dry-run
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import sys, os, re
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from collections import defaultdict
|
|
13
|
+
|
|
14
|
+
from _utils import parse_frontmatter
|
|
15
|
+
|
|
16
|
+
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
17
|
+
PROJECT_ROOT = os.path.dirname(SCRIPTS_DIR)
|
|
18
|
+
DEFAULT_SOURCE = os.path.join(PROJECT_ROOT, 'output', 'biz-daily')
|
|
19
|
+
|
|
20
|
+
TOPIC_ORDER = ['AI', '学术', '新闻', '文学', '投资', '政治']
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def collect_articles(date_dir: str) -> list[dict]:
|
|
24
|
+
"""收集目录下所有文章,提取元数据。"""
|
|
25
|
+
articles = []
|
|
26
|
+
for topic in TOPIC_ORDER:
|
|
27
|
+
topic_dir = Path(date_dir) / topic
|
|
28
|
+
if not topic_dir.is_dir():
|
|
29
|
+
continue
|
|
30
|
+
for md_file in sorted(topic_dir.glob('*.md')):
|
|
31
|
+
try:
|
|
32
|
+
content = md_file.read_text(encoding='utf-8')
|
|
33
|
+
except Exception:
|
|
34
|
+
continue
|
|
35
|
+
fm, body = parse_frontmatter(content)
|
|
36
|
+
# 检查是否已经有相关阅读段落
|
|
37
|
+
if '## 相关阅读' in body:
|
|
38
|
+
continue # 已处理,跳过
|
|
39
|
+
|
|
40
|
+
articles.append({
|
|
41
|
+
'path': md_file,
|
|
42
|
+
'topic': topic,
|
|
43
|
+
'filename': f'{topic}/{md_file.name}',
|
|
44
|
+
'title': fm.get('title', md_file.stem),
|
|
45
|
+
'source': fm.get('source', ''),
|
|
46
|
+
'tags': fm.get('tags', []),
|
|
47
|
+
'concepts': fm.get('concepts', fm.get('wikilinks', [])),
|
|
48
|
+
'relevance': fm.get('relevance', ''),
|
|
49
|
+
})
|
|
50
|
+
return articles
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def find_related(article: dict, all_articles: list[dict]) -> list[dict]:
|
|
54
|
+
"""查找与给定文章相关的文章。"""
|
|
55
|
+
# 同主题文章(排除自身)
|
|
56
|
+
same_topic = [a for a in all_articles
|
|
57
|
+
if a['topic'] == article['topic']
|
|
58
|
+
and a['filename'] != article['filename']]
|
|
59
|
+
|
|
60
|
+
# 共享概念的文章
|
|
61
|
+
my_concepts = set(article['concepts']) if isinstance(article['concepts'], list) else set()
|
|
62
|
+
shared_concept = []
|
|
63
|
+
if my_concepts:
|
|
64
|
+
shared_concept = [a for a in all_articles
|
|
65
|
+
if a['filename'] != article['filename']
|
|
66
|
+
and a['topic'] != article['topic']
|
|
67
|
+
and set(a['concepts'] if isinstance(a['concepts'], list) else []) & my_concepts]
|
|
68
|
+
|
|
69
|
+
# 优先:同主题 + 高相关 + 共享概念
|
|
70
|
+
related = []
|
|
71
|
+
seen = set()
|
|
72
|
+
|
|
73
|
+
# 先加同主题高相关
|
|
74
|
+
for a in same_topic:
|
|
75
|
+
if a['relevance'] == '高':
|
|
76
|
+
related.append(a)
|
|
77
|
+
seen.add(a['filename'])
|
|
78
|
+
|
|
79
|
+
# 共享概念
|
|
80
|
+
for a in shared_concept:
|
|
81
|
+
if a['filename'] not in seen:
|
|
82
|
+
related.append(a)
|
|
83
|
+
seen.add(a['filename'])
|
|
84
|
+
|
|
85
|
+
# 补充同主题中相关
|
|
86
|
+
for a in same_topic:
|
|
87
|
+
if a['filename'] not in seen and a['relevance'] == '中':
|
|
88
|
+
related.append(a)
|
|
89
|
+
seen.add(a['filename'])
|
|
90
|
+
|
|
91
|
+
# 最后补任意来源
|
|
92
|
+
for a in same_topic:
|
|
93
|
+
if a['filename'] not in seen:
|
|
94
|
+
related.append(a)
|
|
95
|
+
seen.add(a['filename'])
|
|
96
|
+
|
|
97
|
+
return related[:5]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def enrich_article(article: dict, related: list[dict], dry_run=False):
|
|
101
|
+
"""为文章末尾追加相关阅读段落。"""
|
|
102
|
+
if not related:
|
|
103
|
+
return 0
|
|
104
|
+
|
|
105
|
+
lines = ['', '---', '', '## 相关阅读', '']
|
|
106
|
+
for a in related:
|
|
107
|
+
label = f"📎 {a['title']}"
|
|
108
|
+
if a.get('source'):
|
|
109
|
+
label += f" — {a['source']}"
|
|
110
|
+
# 使用相对路径 Wikilink
|
|
111
|
+
link_path = a['filename'].replace('/', '/')
|
|
112
|
+
lines.append(f'- [[{link_path}|{label}]]')
|
|
113
|
+
|
|
114
|
+
appendix = '\n'.join(lines) + '\n'
|
|
115
|
+
|
|
116
|
+
if dry_run:
|
|
117
|
+
print(f' → {article["title"][:40]}')
|
|
118
|
+
print(f' 相关: {", ".join(a["title"][:30] for a in related)}')
|
|
119
|
+
return len(related)
|
|
120
|
+
|
|
121
|
+
filepath = article['path']
|
|
122
|
+
current = filepath.read_text(encoding='utf-8')
|
|
123
|
+
filepath.write_text(current.rstrip() + '\n' + appendix, encoding='utf-8')
|
|
124
|
+
return len(related)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def main():
|
|
128
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
129
|
+
import argparse
|
|
130
|
+
parser = argparse.ArgumentParser(description='为文章添加双向链接(相关阅读)')
|
|
131
|
+
parser.add_argument('--date', required=True, help='日期 YYYY-MM-DD')
|
|
132
|
+
parser.add_argument('--dry-run', action='store_true', help='仅预览不写入')
|
|
133
|
+
parser.add_argument('--source', default=DEFAULT_SOURCE, help='源目录')
|
|
134
|
+
args = parser.parse_args()
|
|
135
|
+
|
|
136
|
+
date_dir = os.path.join(args.source, args.date)
|
|
137
|
+
if not os.path.isdir(date_dir):
|
|
138
|
+
print(f'[ERROR] 目录不存在: {date_dir}')
|
|
139
|
+
sys.exit(1)
|
|
140
|
+
|
|
141
|
+
articles = collect_articles(date_dir)
|
|
142
|
+
print(f'找到 {len(articles)} 篇文章')
|
|
143
|
+
print(f'主题分布: {dict((t, len([a for a in articles if a["topic"]==t])) for t in TOPIC_ORDER if any(a["topic"]==t for a in articles))}')
|
|
144
|
+
print()
|
|
145
|
+
|
|
146
|
+
enriched = 0
|
|
147
|
+
skipped = 0
|
|
148
|
+
for article in articles:
|
|
149
|
+
related = find_related(article, articles)
|
|
150
|
+
if not related:
|
|
151
|
+
skipped += 1
|
|
152
|
+
continue
|
|
153
|
+
n = enrich_article(article, related, args.dry_run)
|
|
154
|
+
if n > 0:
|
|
155
|
+
enriched += 1
|
|
156
|
+
|
|
157
|
+
print(f'\n✓ 完成: {enriched} 篇已增强, {skipped} 篇无关联文章')
|
|
158
|
+
if args.dry_run:
|
|
159
|
+
print(' (--dry-run 模式,未实际写入)')
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
if __name__ == '__main__':
|
|
163
|
+
main()
|