-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.py
More file actions
71 lines (58 loc) · 2.14 KB
/
init.py
File metadata and controls
71 lines (58 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import asyncio
import json
import logging
from pathlib import Path
from pymax import MaxClient
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger("MAX_SESSION_LISTER")
WORK_DIR = Path(__file__).parent
CONFIG_FILE = WORK_DIR / "config.json"
def load_config():
try:
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except Exception as e:
logger.error(f"Не удалось загрузить config.json: {e}")
return {}
async def list_chats_for_session(session_cfg):
work_dir = Path(session_cfg.get("work_dir", "sessions/session"))
work_dir.mkdir(parents=True, exist_ok=True)
client = MaxClient(
phone=session_cfg["max_phone"],
work_dir=str(work_dir),
send_fake_telemetry=session_cfg.get("send_fake_telemetry", True),
logger=logger
)
@client.on_start
async def after_authorization():
for chat in client.chats:
title = getattr(chat, "title", None) or getattr(chat, "name", None) or getattr(chat, "label", None)
if not title:
try:
title = str(chat.id)
except Exception:
title = "<неизвестно>"
logger.info(f"Title: '{title}', ID: {chat.id}")
await client.start()
async def main():
cfg = load_config()
sessions = cfg.get("sessions", [])
if not sessions:
logger.warning("Сессии не найдены в config.json")
return
for i, s in enumerate(sessions):
phone = s.get("max_phone", "<нет телефона>")
wd = s.get("work_dir", "<нет work_dir>")
logger.info(f"[{i}] {phone} -> {wd}")
idx = input("Выберите индекс сессии: ").strip()
try:
idx = int(idx)
except Exception:
logger.error("Неверный индекс")
return
if idx < 0 or idx >= len(sessions):
logger.error("Индекс вне диапазона")
return
await list_chats_for_session(sessions[idx])
if __name__ == "__main__":
asyncio.run(main())