feat: add subscribtion scheduler with ai, pagination

This commit is contained in:
Faynot
2026-03-29 11:25:31 +03:00
parent 1db524f757
commit 164acd6307
16 changed files with 688 additions and 358 deletions

View File

@@ -15,6 +15,29 @@ class Database:
preferences TEXT
)
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS sent_vacancies (
user_id INTEGER,
vacancy_url TEXT,
PRIMARY KEY (user_id, vacancy_url)
)
""")
await db.commit()
async def is_vacancy_sent(self, user_id: int, url: str) -> bool:
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM sent_vacancies WHERE user_id = ? AND vacancy_url = ?",
(user_id, url)
) as cursor:
return await cursor.fetchone() is not None
async def mark_vacancy_as_sent(self, user_id: int, url: str):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"INSERT OR IGNORE INTO sent_vacancies (user_id, vacancy_url) VALUES (?, ?)",
(user_id, url)
)
await db.commit()
async def add_user(self, user_id: int):
@@ -44,3 +67,18 @@ class Database:
(user_id,)
) as cursor:
return await cursor.fetchone()
async def count_users(self) -> int:
#Возвращает количество зарегистрированных пользователей
async with aiosqlite.connect(self.db_path) as db:
async with db.execute("SELECT COUNT(*) FROM users") as cursor:
result = await cursor.fetchone()
return result[0] if result else 0
async def clear_sent_vacancies(self, user_id: int):
#Очищает историю отправленных вакансий для пользователя
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"DELETE FROM sent_vacancies WHERE user_id = ?",
(user_id,)
)
await db.commit()