- Telegram collector (Telethon MTProto) with checkpoint-based message fetching - Claude API summarization via proxy (haiku model) - Dashboard page with date picker, markdown summary, raw message drill-down - Separate container lifecycle from dashboard for stable Telethon sessions - Shared SQLite DB mounted read-only into dashboard
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from db import init_db
|
||||
from collector import collect_messages
|
||||
from summarizer import summarize
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
CST = timezone(timedelta(hours=8))
|
||||
SUMMARY_HOUR = int(os.environ.get("SUMMARY_HOUR", 23))
|
||||
COLLECT_INTERVAL = 300 # 5 minutes
|
||||
|
||||
async def main():
|
||||
await init_db()
|
||||
log.info("Chat summarizer started (summary hour=%d CST)", SUMMARY_HOUR)
|
||||
|
||||
last_summary_date = None
|
||||
|
||||
while True:
|
||||
try:
|
||||
await collect_messages()
|
||||
except Exception as e:
|
||||
log.error("Collection error: %s", e)
|
||||
|
||||
now = datetime.now(CST)
|
||||
today = now.strftime("%Y-%m-%d")
|
||||
if now.hour >= SUMMARY_HOUR and last_summary_date != today:
|
||||
try:
|
||||
await summarize(today)
|
||||
last_summary_date = today
|
||||
except Exception as e:
|
||||
log.error("Summary error: %s", e)
|
||||
|
||||
await asyncio.sleep(COLLECT_INTERVAL)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user