updated weather and events

This commit is contained in:
Tenzing Kandang 2026-04-16 17:14:01 +02:00
parent e96a1b9161
commit e0e7d8655c
2 changed files with 12 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import sqlite3
class UserLocation:
def __init__(self, db_name='user_location.db'):
def __init__(self, db_name='users_location.db'):
self.db_name = db_name
self.create_table()
@ -10,6 +10,7 @@ class UserLocation:
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_locations (
username TEXT NOT NULL,
user_id INTEGER PRIMARY KEY,
location TEXT NOT NULL
)
@ -17,11 +18,11 @@ class UserLocation:
conn.commit()
conn.close()
def set_user_location(self, user_id: int, location: str):
def set_user_location(self, username:str, user_id: int, location: str):
conn = sqlite3.connect(self.db_name)
cursor = conn.cursor()
cursor.execute('''
INSERT INTO user_locations (username, user_id, location) VALUES (?, ?) ON CONFLICT(user_id) DO UPDATE SET location=excluded.location''', (username, user_id, location))
INSERT INTO user_locations (username, user_id, location) VALUES (?, ?, ?) ON CONFLICT(user_id) DO UPDATE SET location=excluded.location''', (username, user_id, location))
conn.commit()
conn.close()

11
main.py
View File

@ -95,7 +95,7 @@ class TaskSelect(Select):
updated = await asyncio.to_thread(lambda: service.tasks().update(tasklist=tasklist_id, task=task_id, body=body).execute())
if updated.get("status") == "completed":
await interaction.followup.send(f"User: {interaction.user.display_name} marked task: '{updated.get('title')}' as completed.", ephemeral=True)
await interaction.followup.send(f"User {interaction.user.display_name} marked task '{updated.get('title')}' as completed.", ephemeral=True)
print(f"User {interaction.user.display_name} just completed task {updated.get('title')}")
username = interaction.user.display_name
user_id = interaction.user.id
@ -203,7 +203,6 @@ async def events(interaction: discord.Interaction):
print(f"Start of week: {start_of_week.isoformat()}, End of week: {end_of_week.isoformat()}")
try:
events_result = service.events().list(
calendarId='primary',
@ -230,6 +229,12 @@ async def events(interaction: discord.Interaction):
)
for event in events:
event_description = event.get('description', '')
if 'tasks.google.com' in event_description:
continue
event_time_str = event['start'].get('dateTime', event['start'].get('date'))
if 'Z' in event_time_str:
event_time = datetime.datetime.fromisoformat(event_time_str.replace('Z', '+00:00'))
@ -238,7 +243,6 @@ async def events(interaction: discord.Interaction):
event_time_local = event_time.strftime("%A, %B %d, %Y, %H:%M")
event_description = event.get('description')
task = f"**{event['summary']}**\n{event_time_local}\n Description: {event_description}"
embed.add_field(name="\u200b", value=task, inline=False)
@ -255,6 +259,7 @@ async def set_location(ctx, *, location: str):
username = ctx.author.display_name
user_location_db.set_user_location(username, user_id, location)
await ctx.send(f"Location set to: {location}")
print(f"{username} just set location to {location}")
@bot.tree.command(name="weather", description="Check the weather!")
async def current_weather(interaction: discord.Interaction, location: str = None):