bot y automatización
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from telegram import Bot
|
||||
import telebot
|
||||
import threading
|
||||
from sqlalchemy.orm import Session
|
||||
from database import get_db
|
||||
from models import NewsItem
|
||||
@ -17,7 +18,11 @@ logging.basicConfig(
|
||||
TOKEN = "7626026035:AAHEMp_iIN3y8AwywL0R6OTQvNi7EcJZ0iY"
|
||||
CHAT_ID = "-4731993289" # Reemplaza con el ID del grupo
|
||||
|
||||
bot = Bot(token=TOKEN)
|
||||
bot = telebot.TeleBot(token=TOKEN)
|
||||
|
||||
@bot.message_handler(commands=["start", "help"])
|
||||
def send_welcome(message):
|
||||
bot.reply_to(message, "Welcome to YourBot! Type /info to get more information.")
|
||||
|
||||
async def enviar_mensaje(mensaje: str):
|
||||
try:
|
||||
@ -66,6 +71,8 @@ def obtener_titulares_por_keyword():
|
||||
finally:
|
||||
db.close() # Cerrar la conexión
|
||||
|
||||
|
||||
@bot.message_handler(commands=["resumen"])
|
||||
def enviar_resumen_diario():
|
||||
"""
|
||||
Construye el mensaje con los titulares por keyword y lo envía por Telegram.
|
||||
@ -85,3 +92,13 @@ def enviar_resumen_diario():
|
||||
|
||||
# Enviar mensaje de forma asíncrona
|
||||
asyncio.create_task(enviar_mensaje(mensaje))
|
||||
|
||||
# Función para correr el bot en un hilo separado
|
||||
def start_bot():
|
||||
logging.info("Iniciando el bot")
|
||||
bot.infinity_polling()
|
||||
|
||||
# Iniciar en un hilo separado (solo cuando se llame explícitamente)
|
||||
def run():
|
||||
thread = threading.Thread(target=start_bot, daemon=True)
|
||||
thread.start()
|
Reference in New Issue
Block a user