5aa2a9e384
- Bot token/用户名全局替换:WeatherQuant_bot → polyyuanbot - 群 ID 更新为新群 polyweather售后群(-1003927451869) - 群邀请链接更新为 https://t.me/+Io5H9oVHFmVjOTQ5 - 修复机场推送:Paris/Taipei/Denver/Tel Aviv 支持 airport_primary/current 回退 - 修复跑道数据展示:has_runway 直接检测数据而非依赖 source 字段 - 创建新群 30 城 Forum Topics(data/city_thread_ids.json) - 配置 AMSC AWOS 数据源 URL Constraint: 旧 Telegram 账号已注销,Bot 完全重建 Tested: VPS 部署验证,所有城市推送正常,Topic 路由生效
73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
"""扫描群组内所有 Forum Topic,打印名称和 thread_id。"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
|
import requests
|
|
|
|
|
|
def _load_env() -> None:
|
|
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
env_path = os.path.join(root, ".env")
|
|
if not os.path.isfile(env_path):
|
|
return
|
|
with open(env_path, "r", encoding="utf-8") as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if not line or line.startswith("#") or "=" not in line:
|
|
continue
|
|
key, _, value = line.partition("=")
|
|
key = key.strip()
|
|
if key in os.environ:
|
|
continue
|
|
os.environ[key] = value.strip().strip('"').strip("'")
|
|
|
|
|
|
_load_env()
|
|
TOKEN = os.getenv("TELEGRAM_BOT_TOKEN", "").strip()
|
|
CHAT_ID = -1003927451869
|
|
|
|
|
|
def _try_get_topic(tid: int) -> dict | None:
|
|
try:
|
|
r = requests.get(
|
|
f"https://api.telegram.org/bot{TOKEN}/getForumTopic",
|
|
params={"chat_id": CHAT_ID, "message_thread_id": tid},
|
|
timeout=10,
|
|
)
|
|
data = r.json()
|
|
if data.get("ok"):
|
|
name = (data.get("result") or {}).get("name", "")
|
|
return {"thread_id": tid, "name": name}
|
|
except Exception:
|
|
pass
|
|
return None
|
|
|
|
|
|
def main() -> int:
|
|
if not TOKEN:
|
|
print("未设置 TELEGRAM_BOT_TOKEN", file=sys.stderr)
|
|
return 1
|
|
|
|
print("扫描群组话题...")
|
|
topics = []
|
|
with ThreadPoolExecutor(max_workers=10) as pool:
|
|
futures = {pool.submit(_try_get_topic, tid): tid for tid in range(1, 101)}
|
|
for future in as_completed(futures):
|
|
result = future.result()
|
|
if result:
|
|
topics.append(result)
|
|
print(f" thread_id={result['thread_id']} {result['name']}")
|
|
|
|
topics.sort(key=lambda t: t["thread_id"])
|
|
print(f"\n共 {len(topics)} 个话题:")
|
|
for t in topics:
|
|
print(f" {t['thread_id']:>4} {t['name']}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|