asemxin commited on
Commit ·
105fd67
1
Parent(s): b31c8c5
fix: limit 1050 + 修复图片处理逻辑被移出循环的bug
Browse files- image_daemon.py +8 -5
image_daemon.py
CHANGED
|
@@ -58,7 +58,7 @@ def get_bot_chats(token):
|
|
| 58 |
log(f"❌ get_bot_chats 异常: {type(e).__name__}: {e}")
|
| 59 |
return []
|
| 60 |
|
| 61 |
-
def get_recent_messages(token, chat_id, limit=
|
| 62 |
"""获取聊天中最近的消息"""
|
| 63 |
try:
|
| 64 |
headers = {"Authorization": f"Bearer {token}"}
|
|
@@ -140,7 +140,6 @@ def upload_image(data):
|
|
| 140 |
|
| 141 |
# 2. Telegraph (Telegra.ph) — 无需 API key
|
| 142 |
try:
|
| 143 |
-
import base64
|
| 144 |
# Telegraph 的图片上传接口
|
| 145 |
resp = requests.post("https://telegra.ph/upload",
|
| 146 |
files={"file": ("img.jpg", data, "image/jpeg")}, timeout=30)
|
|
@@ -288,9 +287,7 @@ def main():
|
|
| 288 |
|
| 289 |
new_imgs = 0
|
| 290 |
for chat_id in chats:
|
| 291 |
-
|
| 292 |
-
limit = 20 if cycle == 1 else 10
|
| 293 |
-
messages = get_recent_messages(token, chat_id, limit=limit)
|
| 294 |
|
| 295 |
# 首轮打印所有消息类型统计
|
| 296 |
if cycle == 1:
|
|
@@ -301,11 +298,13 @@ def main():
|
|
| 301 |
log(f"📊 聊天 {chat_id[:12]}... 共 {len(messages)} 条消息")
|
| 302 |
log(f" 消息类型分布: {type_counts}")
|
| 303 |
|
|
|
|
| 304 |
for msg in messages:
|
| 305 |
msg_id = msg.get("message_id", "")
|
| 306 |
if msg_id in processed:
|
| 307 |
continue
|
| 308 |
processed.add(msg_id)
|
|
|
|
| 309 |
|
| 310 |
msg_type = msg.get("msg_type", "")
|
| 311 |
sender_type = msg.get("sender", {}).get("sender_type", "")
|
|
@@ -319,6 +318,10 @@ def main():
|
|
| 319 |
process_message(token, chat_id, msg)
|
| 320 |
new_imgs += 1
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
if new_imgs > 0:
|
| 323 |
save_processed(processed)
|
| 324 |
|
|
|
|
| 58 |
log(f"❌ get_bot_chats 异常: {type(e).__name__}: {e}")
|
| 59 |
return []
|
| 60 |
|
| 61 |
+
def get_recent_messages(token, chat_id, limit=50):
|
| 62 |
"""获取聊天中最近的消息"""
|
| 63 |
try:
|
| 64 |
headers = {"Authorization": f"Bearer {token}"}
|
|
|
|
| 140 |
|
| 141 |
# 2. Telegraph (Telegra.ph) — 无需 API key
|
| 142 |
try:
|
|
|
|
| 143 |
# Telegraph 的图片上传接口
|
| 144 |
resp = requests.post("https://telegra.ph/upload",
|
| 145 |
files={"file": ("img.jpg", data, "image/jpeg")}, timeout=30)
|
|
|
|
| 287 |
|
| 288 |
new_imgs = 0
|
| 289 |
for chat_id in chats:
|
| 290 |
+
messages = get_recent_messages(token, chat_id)
|
|
|
|
|
|
|
| 291 |
|
| 292 |
# 首轮打印所有消息类型统计
|
| 293 |
if cycle == 1:
|
|
|
|
| 298 |
log(f"📊 聊天 {chat_id[:12]}... 共 {len(messages)} 条消息")
|
| 299 |
log(f" 消息类型分布: {type_counts}")
|
| 300 |
|
| 301 |
+
new_in_chat = 0
|
| 302 |
for msg in messages:
|
| 303 |
msg_id = msg.get("message_id", "")
|
| 304 |
if msg_id in processed:
|
| 305 |
continue
|
| 306 |
processed.add(msg_id)
|
| 307 |
+
new_in_chat += 1
|
| 308 |
|
| 309 |
msg_type = msg.get("msg_type", "")
|
| 310 |
sender_type = msg.get("sender", {}).get("sender_type", "")
|
|
|
|
| 318 |
process_message(token, chat_id, msg)
|
| 319 |
new_imgs += 1
|
| 320 |
|
| 321 |
+
if new_in_chat > 0 or cycle % 20 == 0:
|
| 322 |
+
log(f"📊 chat={chat_id[:12]}... 拉取 {len(messages)} 条, 新 {new_in_chat} 条, 已知 {len(processed)} 条")
|
| 323 |
+
|
| 324 |
+
|
| 325 |
if new_imgs > 0:
|
| 326 |
save_processed(processed)
|
| 327 |
|