mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 21:35:19 +00:00
feat: Implement LLM and scheduler modules
- Implement `llm.py` with OpenAI API integration for smart responses. - Implement `scheduler.py` to send a daily summary to the bot owner using `python-telegram-bot`'s `JobQueue`. - Integrate the scheduler into the main application. - Add `pytz` as a new dependency. - Update `tasks.md` to mark all tasks as complete.
This commit is contained in:
@@ -1,27 +1,54 @@
|
||||
# app/scheduler.py
|
||||
import logging
|
||||
from datetime import time
|
||||
from telegram.ext import ContextTypes
|
||||
import pytz
|
||||
|
||||
import schedule
|
||||
import time
|
||||
from datetime import datetime
|
||||
from app.config import OWNER_CHAT_ID, TIMEZONE
|
||||
from app.modules.agenda import get_agenda
|
||||
|
||||
from config import TIMEZONE
|
||||
# Enable logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def send_daily_summary():
|
||||
"""
|
||||
Sends the daily summary to the owner.
|
||||
"""
|
||||
print(f"[{datetime.now()}] Sending daily summary...")
|
||||
# TODO: Implement the logic to fetch and send the summary
|
||||
async def send_daily_summary(context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Sends the daily summary to the owner."""
|
||||
job = context.job
|
||||
chat_id = job.chat_id
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main function to run the scheduler.
|
||||
"""
|
||||
schedule.every().day.at("07:00").do(send_daily_summary)
|
||||
logger.info(f"Running daily summary job for chat_id: {chat_id}")
|
||||
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
||||
try:
|
||||
agenda_text = get_agenda()
|
||||
summary_text = f"🔔 *Resumen Diario - Buen día, Marco!*\n\n{agenda_text}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
text=summary_text,
|
||||
parse_mode='Markdown'
|
||||
)
|
||||
logger.info(f"Successfully sent daily summary to {chat_id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send daily summary to {chat_id}: {e}")
|
||||
|
||||
def schedule_daily_summary(application) -> None:
|
||||
"""Schedules the daily summary job."""
|
||||
if not OWNER_CHAT_ID:
|
||||
logger.warning("OWNER_CHAT_ID not set. Daily summary will not be scheduled.")
|
||||
return
|
||||
|
||||
job_queue = application.job_queue
|
||||
|
||||
# Use the timezone from config
|
||||
tz = pytz.timezone(TIMEZONE)
|
||||
|
||||
# Schedule the job to run every day at 7:00 AM
|
||||
scheduled_time = time(hour=7, minute=0, tzinfo=tz)
|
||||
|
||||
job_queue.run_daily(
|
||||
send_daily_summary,
|
||||
time=scheduled_time,
|
||||
chat_id=int(OWNER_CHAT_ID),
|
||||
name="daily_summary"
|
||||
)
|
||||
|
||||
logger.info(f"Scheduled daily summary for {OWNER_CHAT_ID} at {scheduled_time} {TIMEZONE}")
|
||||
|
||||
Reference in New Issue
Block a user