Added account checker

This commit is contained in:
Joan
2023-07-04 22:10:00 +02:00
parent ab68730aab
commit 1665ab4bf7
3 changed files with 26 additions and 0 deletions

View File

@@ -127,6 +127,10 @@ def get_modified_date(article):
article_date = article['modification_date'] 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") 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): async def send_article(article, product):
application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build() application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build()
create_image(article) create_image(article)

View File

@@ -215,6 +215,24 @@ def get_user_until(telegram_user_id):
con.close() con.close()
return ret 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): def get_product(product):
product_name = product.get('product_name').lower() product_name = product.get('product_name').lower()
telegram_user_id = product.get('telegram_user_id') telegram_user_id = product.get('telegram_user_id')

View File

@@ -3,6 +3,7 @@ import logging
import helpers import helpers
import walladb import walladb
import constants import constants
import account_checker
from worker import Worker from worker import Worker
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply
@@ -445,6 +446,9 @@ def main()->None:
p.start() p.start()
SEARCH_THREADS_LIST.append((product, p)) SEARCH_THREADS_LIST.append((product, p))
p = threading.Thread(target=account_checker.account_checker, args=(3600))
p.start()
"""Start the bot.""" """Start the bot."""
# Create the Application and pass it your bot's token. # 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() application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build()