Added multiuser branch

This commit is contained in:
Joan Cano
2023-03-04 22:57:05 +01:00
parent da20bfe5a5
commit 2abff6dddb
2 changed files with 18 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import threading
import logging
import prettytable
import helpers
import walladb
from worker import Worker
from telegram import Update
@@ -127,6 +128,7 @@ async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
await update.message.reply_markdown_v2(f'```{(table)}```')
def main()->None:
walladb.setup_db()
products = parse_json_file()
for product in products:

16
wallamanta/walladb.py Normal file
View File

@@ -0,0 +1,16 @@
import sqlite3
DB = "/app/data/wallamanta.db"
def setup_db():
con = sqlite3.connect(DB)
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS users(telegram_user_id, telegram_user, active)")
cur.execute("CREATE TABLE IF NOT EXISTS products(product_name, distance, latitude, longitude, condition, min_price, max_price, title_keyword_exclude, exclude, telegram_user_id)")
con.close()
def is_user_valid(telegram_user_id):
con = sqlite3.connect(DB)
cur = con.cursor()
res = cur.execute(f"SELECT * FROM users WHERE telegram_user_id={telegram_user_id}")
return res.fetchone() is None