Files
inversionitasbot/app/main.py

30 lines
849 B
Python

from fastapi import FastAPI
from database import Base, engine
from routes import router
from apscheduler.schedulers.background import BackgroundScheduler
from contextlib import asynccontextmanager
from telegrambot import enviar_mensaje_sync
#from webscrapper import ejecutar_scrapper
# Crear las tablas en MySQL si no existen
Base.metadata.create_all(bind=engine)
# Inicializar FastAPI
app = FastAPI()
scheduler = BackgroundScheduler()
def tarea_programada():
enviar_mensaje_sync("¡Buenos días! Aquí tienes tu mensaje diario.")
scheduler.add_job(tarea_programada, "cron", hour=8, minute=0)
@asynccontextmanager
async def lifespan(app: FastAPI):
scheduler.start() # Iniciar el scheduler cuando la app arranca
yield
scheduler.shutdown() # Apagar el scheduler al cerrar la app
# Incluir rutas
app.include_router(router)