mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-13 21:35:19 +00:00
Merge branch 'main' into feat/add-print-command-8512170790091266484
This commit is contained in:
@@ -89,3 +89,28 @@ def create_event(summary, start_time, end_time, attendees, calendar_id=CALENDAR_
|
||||
except HttpError as error:
|
||||
print(f"An error occurred: {error}")
|
||||
return None
|
||||
|
||||
|
||||
def get_events_for_day(date, calendar_id=CALENDAR_ID):
|
||||
"""
|
||||
Fetches all events for a given day from the calendar.
|
||||
"""
|
||||
try:
|
||||
time_min = date.isoformat() + "T00:00:00Z"
|
||||
time_max = date.isoformat() + "T23:59:59Z"
|
||||
|
||||
events_result = (
|
||||
service.events()
|
||||
.list(
|
||||
calendarId=calendar_id,
|
||||
timeMin=time_min,
|
||||
timeMax=time_max,
|
||||
singleEvents=True,
|
||||
orderBy="startTime",
|
||||
)
|
||||
.execute()
|
||||
)
|
||||
return events_result.get("items", [])
|
||||
except HttpError as error:
|
||||
print(f"An error occurred: {error}")
|
||||
return []
|
||||
|
||||
21
app/llm.py
21
app/llm.py
@@ -1,15 +1,26 @@
|
||||
# app/llm.py
|
||||
|
||||
from config import OPENAI_API_KEY
|
||||
import openai
|
||||
from app.config import OPENAI_API_KEY
|
||||
|
||||
def get_smart_response(prompt):
|
||||
"""
|
||||
Generates a smart response using an LLM.
|
||||
"""
|
||||
|
||||
if not OPENAI_API_KEY:
|
||||
return "OpenAI API key not configured."
|
||||
|
||||
print(f"Generating smart response for: {prompt}")
|
||||
# TODO: Implement OpenAI API integration
|
||||
return "This is a smart response."
|
||||
openai.api_key = OPENAI_API_KEY
|
||||
|
||||
try:
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": prompt},
|
||||
],
|
||||
)
|
||||
return response.choices[0].message.content.strip()
|
||||
except Exception as e:
|
||||
print(f"An error occurred with OpenAI: {e}")
|
||||
return "I'm sorry, I couldn't generate a response right now."
|
||||
|
||||
@@ -28,7 +28,7 @@ from modules.equipo import (
|
||||
from modules.aprobaciones import view_pending, handle_approval_action
|
||||
from modules.servicios import get_service_info
|
||||
from modules.admin import get_system_status
|
||||
from modules.print import print_handler
|
||||
from app.scheduler import setup_scheduler
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(
|
||||
@@ -105,6 +105,9 @@ def main() -> None:
|
||||
application.add_handler(CommandHandler("print", print_handler))
|
||||
application.add_handler(CallbackQueryHandler(button_dispatcher))
|
||||
|
||||
# Set up the scheduler
|
||||
setup_scheduler(application)
|
||||
|
||||
logger.info("Starting Talía Bot...")
|
||||
application.run_polling()
|
||||
|
||||
|
||||
@@ -1,27 +1,52 @@
|
||||
# app/scheduler.py
|
||||
|
||||
import schedule
|
||||
import time
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
import pytz
|
||||
from telegram import Bot
|
||||
from app.config import OWNER_CHAT_ID, TIMEZONE
|
||||
from app.calendar import get_events_for_day
|
||||
|
||||
from config import TIMEZONE
|
||||
|
||||
def send_daily_summary():
|
||||
def format_event_time(start_time_str):
|
||||
"""
|
||||
Formats the event start time into a user-friendly format.
|
||||
"""
|
||||
if "T" in start_time_str: # It's a dateTime
|
||||
dt_object = datetime.datetime.fromisoformat(start_time_str)
|
||||
return dt_object.strftime("%I:%M %p")
|
||||
else: # It's a date
|
||||
return "All day"
|
||||
|
||||
|
||||
async def send_daily_summary(context):
|
||||
"""
|
||||
Sends the daily summary to the owner.
|
||||
"""
|
||||
print(f"[{datetime.now()}] Sending daily summary...")
|
||||
# TODO: Implement the logic to fetch and send the summary
|
||||
bot = context.bot
|
||||
today = datetime.datetime.now(pytz.timezone(TIMEZONE)).date()
|
||||
events = get_events_for_day(today)
|
||||
|
||||
def main():
|
||||
if not events:
|
||||
summary = "Good morning! You have no events scheduled for today."
|
||||
else:
|
||||
summary = "Good morning! Here is your schedule for today:\n\n"
|
||||
for event in events:
|
||||
start = event["start"].get("dateTime", event["start"].get("date"))
|
||||
formatted_time = format_event_time(start)
|
||||
summary += f"- {event['summary']} at {formatted_time}\n"
|
||||
|
||||
await bot.send_message(chat_id=OWNER_CHAT_ID, text=summary)
|
||||
|
||||
|
||||
def setup_scheduler(application):
|
||||
"""
|
||||
Main function to run the scheduler.
|
||||
Sets up the daily summary job.
|
||||
"""
|
||||
schedule.every().day.at("07:00").do(send_daily_summary)
|
||||
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
tz = pytz.timezone(TIMEZONE)
|
||||
job_queue = application.job_queue
|
||||
job_queue.run_daily(
|
||||
send_daily_summary,
|
||||
time=datetime.time(hour=7, minute=0, tzinfo=tz),
|
||||
chat_id=OWNER_CHAT_ID,
|
||||
name="daily_summary",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user