From 1665ab4bf7c7a4c7aacec0a8bcd6a21da9916d3c Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 4 Jul 2023 22:10:00 +0200 Subject: [PATCH] Added account checker --- wallamanta/helpers.py | 4 ++++ wallamanta/walladb.py | 18 ++++++++++++++++++ wallamanta/wallamanta.py | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/wallamanta/helpers.py b/wallamanta/helpers.py index 20fbda3..f3a4e7b 100644 --- a/wallamanta/helpers.py +++ b/wallamanta/helpers.py @@ -127,6 +127,10 @@ def get_modified_date(article): article_date = article['modification_date'] return datetime.fromtimestamp(int(int(article_date)/1000)).astimezone(pytz.timezone("Europe/Madrid")).strftime("%d/%m/%Y - %H:%M:%S") +async def send_message(telegram_user_id, message): + application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build() + await application.bot.send_message(chat_id=telegram_user_id, text=message) + async def send_article(article, product): application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build() create_image(article) diff --git a/wallamanta/walladb.py b/wallamanta/walladb.py index fd4e63f..06a767d 100644 --- a/wallamanta/walladb.py +++ b/wallamanta/walladb.py @@ -215,6 +215,24 @@ def get_user_until(telegram_user_id): con.close() return ret +def deactivate_user(telegram_user_id): + con = connect_db() + cur = con.cursor(prepared=True) + params = (telegram_user_id,) + cur.execute(f"UPDATE users SET active=False WHERE telegram_user_id=%s", params) + con.commit() + con.close() + logging.info(f"De-activated user {helpers.get_telegram_user_name(telegram_user_id)} ({telegram_user_id})") + +def activate_user(telegram_user_id): + con = connect_db() + cur = con.cursor(prepared=True) + params = (telegram_user_id,) + cur.execute(f"UPDATE users SET active=True WHERE telegram_user_id=%s", params) + con.commit() + con.close() + logging.info(f"Activated user {helpers.get_telegram_user_name(telegram_user_id)} ({telegram_user_id})") + def get_product(product): product_name = product.get('product_name').lower() telegram_user_id = product.get('telegram_user_id') diff --git a/wallamanta/wallamanta.py b/wallamanta/wallamanta.py index fefb6f9..c4cc34e 100644 --- a/wallamanta/wallamanta.py +++ b/wallamanta/wallamanta.py @@ -3,6 +3,7 @@ import logging import helpers import walladb import constants +import account_checker from worker import Worker from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply @@ -445,6 +446,9 @@ def main()->None: p.start() SEARCH_THREADS_LIST.append((product, p)) + p = threading.Thread(target=account_checker.account_checker, args=(3600)) + p.start() + """Start the bot.""" # Create the Application and pass it your bot's token. application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build()