From 2abff6dddb86cd88c02b093f9b47558ac2317f2f Mon Sep 17 00:00:00 2001 From: Joan Cano Date: Sat, 4 Mar 2023 22:57:05 +0100 Subject: [PATCH] Added multiuser branch --- wallamanta/alert.py | 2 ++ wallamanta/walladb.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 wallamanta/walladb.py diff --git a/wallamanta/alert.py b/wallamanta/alert.py index 1bd11e9..b70183f 100644 --- a/wallamanta/alert.py +++ b/wallamanta/alert.py @@ -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: diff --git a/wallamanta/walladb.py b/wallamanta/walladb.py new file mode 100644 index 0000000..3bebbec --- /dev/null +++ b/wallamanta/walladb.py @@ -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