telegram-cli-bot/add_channels.py

56 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Утилита для пакетного добавления Telegram-каналов
"""
import sys
import os
import json
# Добавляем корень проекта в path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from bot.tools.telegram_web_tool import load_subscriptions, save_subscriptions
def add_channels(channel_names: list):
"""Добавить список каналов"""
channels = load_subscriptions()
added = []
already_exists = []
for name in channel_names:
name = name.strip().lstrip('@')
if not name:
continue
if name in channels:
already_exists.append(name)
else:
channels.append(name)
added.append(name)
save_subscriptions(channels)
print(f"✅ Добавлено каналов: {len(added)}")
for ch in added:
print(f" + @{ch}")
if already_exists:
print(f"\n⚠️ Уже существуют: {len(already_exists)}")
for ch in already_exists:
print(f" - @{ch}")
print(f"\n📊 Всего каналов: {len(channels)}")
if __name__ == '__main__':
# Каналы из запроса Владимира
channels_str = "bbbreaking, godnotech, localhost_public, angarsk38, itmemas, ithueti, ai_exee, Agitblog, pbdsu, bash_help, krxnotes"
# Разделяем по запятой
channel_list = [ch.strip() for ch in channels_str.split(',')]
add_channels(channel_list)