feat(digest): 每天把当天视频情况画成一张图推到企业微信
运营要看的是「他们今天发了什么」,文字版在企业微信手机上没法对齐, 所以直接用 PIL 画成表:博主 / 标题 / 点赞 / 评论 / 收藏 / 分享, 按发布时间取当天,指标取最近一轮,按点赞降序。 - 播放量没进表:抖音对普通作品恒返回 0,摆一列 0 只会误导 - 定时按「今天发过没有」判断,进程重启也不会重复推 - 发送失败不写标记,下一拍继续重试 - 设置页有开关和时间;Webhook 面板加了「预览今天」和「发今天图」 - 容器需要中文字体,Dockerfile 装上 fonts-wqy-zenhei
This commit is contained in:
+46
-1
@@ -29,7 +29,17 @@ from tools.time_util import get_current_timestamp
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from ..monitor import covers, douyin_api, notify, qrlogin, report, service, tagrules, upstream
|
||||
from ..monitor import (
|
||||
covers,
|
||||
digest,
|
||||
douyin_api,
|
||||
notify,
|
||||
qrlogin,
|
||||
report,
|
||||
service,
|
||||
tagrules,
|
||||
upstream,
|
||||
)
|
||||
from ..monitor import identities as identity_pool
|
||||
from ..monitor.db import get_session
|
||||
from ..monitor.platforms import PLATFORM_XHS
|
||||
@@ -896,6 +906,41 @@ async def run_upstream_check():
|
||||
return await upstream.run_check(notify_when_new=False)
|
||||
|
||||
|
||||
@router.get("/digest/preview")
|
||||
async def preview_daily_digest(
|
||||
platform: str = Query(default=PLATFORM_XHS),
|
||||
day: Optional[str] = Query(default=None, description="YYYY-MM-DD,省略=今天"),
|
||||
):
|
||||
"""把「今天的视频情况」画出来直接返回图片,**不发消息**。
|
||||
|
||||
先看一眼图长什么样,再去开定时推送 —— 不必为了验证往群里发一条。
|
||||
"""
|
||||
try:
|
||||
target = date.fromisoformat(day) if day else date.today()
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="日期格式应为 YYYY-MM-DD")
|
||||
|
||||
async with get_session() as session:
|
||||
rows = await digest.daily_rows(session, platform, target)
|
||||
label = "抖音" if platform == "dy" else "小红书"
|
||||
image_bytes = digest.render_table(rows, target, label)
|
||||
return Response(content=image_bytes, media_type="image/png")
|
||||
|
||||
|
||||
@router.post("/digest/send")
|
||||
async def send_daily_digest_now(platform: str = Query(default=PLATFORM_XHS)):
|
||||
"""手动生成并发送「今天的视频情况」图。
|
||||
|
||||
定时那条由调度器按设置触发;这个端点存在的意义是**先看一眼图长什么样**,
|
||||
以及确认 Webhook 通不通 —— 不要等到晚上十点才发现发不出去。
|
||||
"""
|
||||
async with get_session() as session:
|
||||
ok, detail, count = await digest.send_daily_digest(session, platform)
|
||||
if not ok:
|
||||
raise HTTPException(status_code=502, detail=detail)
|
||||
return {"ok": True, "rows": count, "detail": detail}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 身份池
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user