daily folder structure: each date gets its own directory
This commit is contained in:
45
tools/deepseek_balance.py
Normal file
45
tools/deepseek_balance.py
Normal file
@ -0,0 +1,45 @@
|
||||
"""Fetch DeepSeek API balance and save to nav page data directory."""
|
||||
import json
|
||||
import os
|
||||
|
||||
import requests
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
API_KEY = "sk-bbca4a0380d549389f0d27cdea0b5228"
|
||||
OUTPUT = "/var/www/nav/data/balance.json"
|
||||
|
||||
tz = timezone(timedelta(hours=8))
|
||||
now = datetime.now(tz).strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
try:
|
||||
resp = requests.get(
|
||||
"https://api.deepseek.com/user/balance",
|
||||
headers={"Authorization": f"Bearer {API_KEY}"},
|
||||
timeout=10,
|
||||
)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
info = data.get("balance_infos", [{}])[0]
|
||||
result = {
|
||||
"available": data.get("is_available", False),
|
||||
"total_balance": info.get("total_balance", "0.00"),
|
||||
"granted_balance": info.get("granted_balance", "0.00"),
|
||||
"topped_up_balance": info.get("topped_up_balance", "0.00"),
|
||||
"currency": info.get("currency", "CNY"),
|
||||
"updated_at": now,
|
||||
"status": "ok",
|
||||
}
|
||||
else:
|
||||
result = {
|
||||
"status": "error",
|
||||
"message": f"HTTP {resp.status_code}",
|
||||
"updated_at": now,
|
||||
}
|
||||
except Exception as e:
|
||||
result = {"status": "error", "message": str(e), "updated_at": now}
|
||||
|
||||
os.makedirs(os.path.dirname(OUTPUT), exist_ok=True)
|
||||
with open(OUTPUT, "w") as f:
|
||||
json.dump(result, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"Written: {result.get('total_balance', 'error')}")
|
||||
@ -1,55 +1,26 @@
|
||||
"""Markdown formatter - converts AI analysis results to beautiful .md files."""
|
||||
"""Markdown formatter -- wraps AI-generated body with frontmatter and annotations."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def format_daily_digest(date, categories, summary, connections, todos):
|
||||
"""Format daily digest markdown file."""
|
||||
def format_daily_digest(date, ai_body):
|
||||
"""Wrap AI-generated Markdown body with frontmatter."""
|
||||
date_str = date.strftime("%Y-%m-%d")
|
||||
weekday = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"][date.weekday()]
|
||||
|
||||
lines = []
|
||||
lines.append("---")
|
||||
lines.append(f"date: {date_str}")
|
||||
lines.append("date: " + date_str)
|
||||
lines.append("type: daily-digest")
|
||||
lines.append("tags: [灵感收集器, 每日总结]")
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append(f"# {date_str} 灵感摘要 · {weekday}")
|
||||
lines.append("# " + date_str + " 灵感摘要 · " + weekday)
|
||||
lines.append("")
|
||||
|
||||
# Summary
|
||||
lines.append("## AI 分析(自动生成,请勿编辑)")
|
||||
lines.append("")
|
||||
lines.append(summary)
|
||||
lines.append(ai_body)
|
||||
lines.append("")
|
||||
|
||||
# Categories
|
||||
if categories:
|
||||
lines.append("### 分类概览")
|
||||
lines.append("")
|
||||
for cat, items in categories.items():
|
||||
count = len(items) if isinstance(items, list) else items
|
||||
lines.append(f"- **{cat}**:{count}条")
|
||||
lines.append("")
|
||||
|
||||
# Connections
|
||||
if connections:
|
||||
lines.append("### 关联发现")
|
||||
lines.append("")
|
||||
for conn in connections:
|
||||
lines.append(f"- {conn}")
|
||||
lines.append("")
|
||||
|
||||
# Todos
|
||||
if todos:
|
||||
lines.append("### 待办")
|
||||
lines.append("")
|
||||
for todo in todos:
|
||||
lines.append(f"- [ ] {todo}")
|
||||
lines.append("")
|
||||
|
||||
# User annotation area
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append("## 我的批注")
|
||||
@ -68,18 +39,16 @@ def format_weekly_trend(start_date, end_date, stats, highlights, insight):
|
||||
|
||||
lines = []
|
||||
lines.append("---")
|
||||
lines.append(f"date: {start_date.year}-W{week_number}")
|
||||
lines.append("date: " + str(start_date.year) + "-W" + str(week_number))
|
||||
lines.append("type: weekly-trend")
|
||||
lines.append("tags: [灵感收集器, 每周趋势]")
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append(f"# 第 {week_number} 周灵感趋势({week_start} - {week_end})")
|
||||
lines.append("# 第 " + str(week_number) + " 周灵感趋势(" + week_start + " - " + week_end + ")")
|
||||
lines.append("")
|
||||
|
||||
# Stats
|
||||
lines.append("## AI 分析(自动生成,请勿编辑)")
|
||||
lines.append("")
|
||||
lines.append(f"本周共记录 **{stats.get('total', 0)}** 条灵感。")
|
||||
lines.append("本周共记录 **" + str(stats.get('total', 0)) + "** 条灵感。")
|
||||
lines.append("")
|
||||
|
||||
if stats.get("daily_counts"):
|
||||
@ -87,22 +56,23 @@ def format_weekly_trend(start_date, end_date, stats, highlights, insight):
|
||||
lines.append("")
|
||||
for day, count in stats["daily_counts"].items():
|
||||
bar = "█" * count if count > 0 else "▏"
|
||||
lines.append(f"- {day}:{bar} {count}条")
|
||||
lines.append("- " + day + ":" + bar + " " + str(count) + "条")
|
||||
lines.append("")
|
||||
|
||||
if stats.get("categories"):
|
||||
lines.append("### 主题分布")
|
||||
lines.append("")
|
||||
total = stats.get("total", 1)
|
||||
for cat, count in stats["categories"].items():
|
||||
pct = count / stats["total"] * 100 if stats["total"] else 0
|
||||
lines.append(f"- **{cat}**:{count}条({pct:.0f}%)")
|
||||
pct = count / total * 100 if total else 0
|
||||
lines.append("- **" + cat + "**:" + str(count) + "条(" + str(int(pct)) + "%)")
|
||||
lines.append("")
|
||||
|
||||
if highlights:
|
||||
lines.append("### 本周亮点")
|
||||
lines.append("")
|
||||
for h in highlights:
|
||||
lines.append(f"- {h}")
|
||||
lines.append("- " + h)
|
||||
lines.append("")
|
||||
|
||||
if insight:
|
||||
@ -111,7 +81,6 @@ def format_weekly_trend(start_date, end_date, stats, highlights, insight):
|
||||
lines.append(insight)
|
||||
lines.append("")
|
||||
|
||||
# User annotation
|
||||
lines.append("---")
|
||||
lines.append("")
|
||||
lines.append("## 我的批注")
|
||||
|
||||
Reference in New Issue
Block a user