Untitled
unknown
plain_text
a month ago
2.2 kB
4
Indexable
from telethon import TelegramClient import asyncio from datetime import datetime, timedelta import pytz # Gestion des fuseaux horaires # 🔹 Remplace ces infos par tes identifiants API Telegram 🔹 API_ID = "TON_API_ID" API_HASH = "TON_API_HASH" PHONE_NUMBER = "+123456789" # Numéro de téléphone Telegram # 🔹 Liste des groupes avec leurs @usernames 🔹 GROUP_USERNAMES = ["@nom_du_groupe1", "@nom_du_groupe2"] # Remplace par les vrais noms # 🔹 Contenu du message 🔹 MESSAGE_TEXT = "Ceci est un message planifié automatiquement !" # 🔹 Intervalle entre chaque envoi (en minutes) 🔹 INTERVAL = 5 # 🔹 Heure de fin (format HH:MM en heure locale) 🔹 END_TIME = "18:00" # 🔹 Fuseau horaire (modifie si besoin, ex: "Europe/London" pour UK) 🔹 LOCAL_TIMEZONE = "Europe/Paris" # Initialisation du client Telegram client = TelegramClient("session_name", API_ID, API_HASH) async def schedule_messages(): await client.start(PHONE_NUMBER) # Gestion du fuseau horaire local_tz = pytz.timezone(LOCAL_TIMEZONE) utc_tz = pytz.utc now = datetime.now(local_tz) end_time = datetime.strptime(END_TIME, "%H:%M").replace(year=now.year, month=now.month, day=now.day) end_time = local_tz.localize(end_time).astimezone(utc_tz) if end_time < now: end_time += timedelta(days=1) # Si l'heure est déjà passée, on programme pour le lendemain next_send_time = now.astimezone(utc_tz) while next_send_time <= end_time: for group_username in GROUP_USERNAMES: try: entity = await client.get_entity(group_username) # Récupérer l'entité via @username await client.send_message(entity, MESSAGE_TEXT, schedule=next_send_time) print(f"✅ Message planifié pour {group_username} à {next_send_time.strftime('%H:%M:%S')} UTC") except Exception as e: print(f"❌ Erreur avec {group_username}: {e}") next_send_time += timedelta(minutes=INTERVAL) print("🎯 Tous les messages ont été planifiés avec succès.") # Lancer le script with client: client.loop.run_until_complete(schedule_messages())
Editor is loading...
Leave a Comment