timezone fix

This commit is contained in:
2026-04-02 09:53:14 +03:00
parent e8544ebb38
commit 684a952158
3 changed files with 67 additions and 30 deletions

View File

@@ -13,7 +13,8 @@ async def init_db():
user_id INTEGER PRIMARY KEY,
lat REAL,
lon REAL,
time TEXT
time TEXT,
timezone TEXT
)
''')
await db.commit()
@@ -25,16 +26,17 @@ async def get_user(user_id: int):
async with db.execute("SELECT * FROM users WHERE user_id = ?", (user_id,)) as cursor:
return await cursor.fetchone()
async def save_user_location(user_id: int, lat: float, lon: float):
"""Сохраняет или обновляет только координаты пользователя."""
async def save_user_location(user_id: int, lat: float, lon: float, timezone: str):
"""Сохраняет или обновляет координаты и часовой пояс пользователя."""
async with aiosqlite.connect(DB_PATH) as db:
await db.execute('''
INSERT INTO users (user_id, lat, lon)
VALUES (?, ?, ?)
INSERT INTO users (user_id, lat, lon, timezone)
VALUES (?, ?, ?, ?)
ON CONFLICT(user_id) DO UPDATE SET
lat=excluded.lat,
lon=excluded.lon
''', (user_id, lat, lon))
lon=excluded.lon,
timezone=excluded.timezone
''', (user_id, lat, lon, timezone))
await db.commit()
async def update_user_time(user_id: int, time: str):