hohoho
This commit is contained in:
parent
1890a8380b
commit
64baba32b4
@ -566,7 +566,7 @@ def sse_events():
|
|||||||
return Response(stream_with_context(event_stream()), mimetype='text/event-stream')
|
return Response(stream_with_context(event_stream()), mimetype='text/event-stream')
|
||||||
def push_feishu(date_str: str, amount: float, reason: str):
|
def push_feishu(date_str: str, amount: float, reason: str):
|
||||||
cfg = load_config()
|
cfg = load_config()
|
||||||
url = cfg.get("feishu_webhook_url") or cfg.get("webhook_url")
|
url = cfg.get("feishu_webhook_url")
|
||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
shop = cfg.get("shop_name", "益选便利店")
|
shop = cfg.get("shop_name", "益选便利店")
|
||||||
@ -623,11 +623,35 @@ def push_feishu(date_str: str, amount: float, reason: str):
|
|||||||
body = json.dumps(payload_obj, ensure_ascii=False).encode('utf-8')
|
body = json.dumps(payload_obj, ensure_ascii=False).encode('utf-8')
|
||||||
return requests.post(u, data=body, headers={'Content-Type': 'application/json; charset=utf-8'}, timeout=5)
|
return requests.post(u, data=body, headers={'Content-Type': 'application/json; charset=utf-8'}, timeout=5)
|
||||||
try:
|
try:
|
||||||
|
is_feishu = ('open.feishu.cn' in url)
|
||||||
|
ok = False
|
||||||
|
if is_feishu:
|
||||||
resp = _post_json(url, payload)
|
resp = _post_json(url, payload)
|
||||||
ok = (200 <= resp.status_code < 300)
|
ok = (200 <= resp.status_code < 300)
|
||||||
_log(f"飞书推送卡片{'成功' if ok else '失败'}: status={resp.status_code} {resp.text[:200]}")
|
_log(f"飞书推送卡片{'成功' if ok else '失败'}: status={resp.status_code} {resp.text[:200]}")
|
||||||
if not ok:
|
if not ok:
|
||||||
text = f"📊 {shop}\n日期:{date_str}\n今日:¥{amount:.2f}"
|
post_payload = {
|
||||||
|
"msg_type": "post",
|
||||||
|
"content": {
|
||||||
|
"post": {
|
||||||
|
"zh_cn": {
|
||||||
|
"title": f"{shop} 营业额通知",
|
||||||
|
"content": [[
|
||||||
|
{"tag":"text","text": f"日期:{date_str}\n"},
|
||||||
|
{"tag":"text","text": f"今日:¥{amount:.2f}"},
|
||||||
|
*( [{"tag":"text","text": f" {arrow} {diff_str} {pct_str}"}] if isinstance(y_amt,(int,float)) else [] ),
|
||||||
|
],[
|
||||||
|
{"tag":"text","text": f"原因:{reason}"}
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp_post = _post_json(url, post_payload)
|
||||||
|
ok = (200 <= resp_post.status_code < 300)
|
||||||
|
_log(f"飞书推送POST{'成功' if ok else '失败'}: status={resp_post.status_code} {resp_post.text[:200]}")
|
||||||
|
if not ok:
|
||||||
|
text = f"{shop}\n日期:{date_str}\n今日:¥{amount:.2f}"
|
||||||
if isinstance(y_amt, (int, float)):
|
if isinstance(y_amt, (int, float)):
|
||||||
text += f" {arrow} {diff_str} {pct_str}".strip()
|
text += f" {arrow} {diff_str} {pct_str}".strip()
|
||||||
text += f"\n原因:{reason}"
|
text += f"\n原因:{reason}"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user