Added account checker
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user