Added more debugging
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.7
|
FROM python:3.11
|
||||||
|
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
ADD . /app
|
ADD . /app
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import logging
|
|||||||
import constants
|
import constants
|
||||||
import pytz
|
import pytz
|
||||||
import walladb
|
import walladb
|
||||||
|
import asyncio
|
||||||
from newrelic_telemetry_sdk import Event, EventClient
|
from newrelic_telemetry_sdk import Event, EventClient
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
@@ -58,6 +59,9 @@ def is_date_expired(until):
|
|||||||
def random_wait():
|
def random_wait():
|
||||||
time.sleep(random.random())
|
time.sleep(random.random())
|
||||||
|
|
||||||
|
async def random_async_wait():
|
||||||
|
await asyncio.sleep(random.random())
|
||||||
|
|
||||||
def download_image(article):
|
def download_image(article):
|
||||||
r = requests.get(article['images'][0]['original'])
|
r = requests.get(article['images'][0]['original'])
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
python-telegram-bot==20.1
|
python-telegram-bot==20.4
|
||||||
python-telegram-bot[job-queue]==20.1
|
python-telegram-bot[job-queue]==20.4
|
||||||
requests==2.28.1
|
requests==2.31.0
|
||||||
prettytable==3.6.0
|
prettytable==3.6.0
|
||||||
Pillow==9.4.0
|
Pillow==9.4.0
|
||||||
mysql-connector-python==8.0.32
|
mysql-connector-python==8.0.32
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import helpers
|
|||||||
import walladb
|
import walladb
|
||||||
import constants
|
import constants
|
||||||
import account_checker
|
import account_checker
|
||||||
|
import time
|
||||||
|
|
||||||
from worker import Worker
|
from worker import Worker
|
||||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply
|
||||||
@@ -437,24 +438,37 @@ async def list_threads(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||||||
else:
|
else:
|
||||||
await update.message.reply_markdown_v2(helpers.telegram_escape_characters(f"{threads_string}"))
|
await update.message.reply_markdown_v2(helpers.telegram_escape_characters(f"{threads_string}"))
|
||||||
|
|
||||||
|
def count_threads():
|
||||||
|
time.sleep(10)
|
||||||
|
while True:
|
||||||
|
logging.info(f"=== There are: {threading.active_count()} threads. ===")
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
def main()->None:
|
def main()->None:
|
||||||
global SEARCH_THREADS_LIST
|
global SEARCH_THREADS_LIST
|
||||||
walladb.setup_db()
|
walladb.setup_db()
|
||||||
products = walladb.get_all_products()
|
products = walladb.get_all_products()
|
||||||
|
|
||||||
|
"""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()
|
||||||
|
|
||||||
|
logging.info(f"Loading {len(products)} products...")
|
||||||
|
count = 0
|
||||||
for product in products:
|
for product in products:
|
||||||
if helpers.is_valid_request(product):
|
if helpers.is_valid_request(product):
|
||||||
|
count = count + 1
|
||||||
logging.info(product)
|
logging.info(product)
|
||||||
p = threading.Thread(target=Worker.run, args=(product, ))
|
p = threading.Thread(target=Worker.run, args=(product, ))
|
||||||
p.start()
|
p.start()
|
||||||
SEARCH_THREADS_LIST.append((product, p))
|
SEARCH_THREADS_LIST.append((product, p))
|
||||||
|
logging.info(f"{count} products finally loaded")
|
||||||
|
|
||||||
p = threading.Thread(target=account_checker.account_checker, args=(3600, ))
|
p = threading.Thread(target=account_checker.account_checker, args=(3600, ))
|
||||||
p.start()
|
p.start()
|
||||||
|
|
||||||
"""Start the bot."""
|
p = threading.Thread(target=count_threads)
|
||||||
# Create the Application and pass it your bot's token.
|
p.start()
|
||||||
application = Application.builder().get_updates_http_version('1.1').http_version('1.1').token(constants.TELEGRAM_TOKEN).build()
|
|
||||||
|
|
||||||
# on different commands - answer in Telegram
|
# on different commands - answer in Telegram
|
||||||
application.add_handler(CommandHandler("help", help_command))
|
application.add_handler(CommandHandler("help", help_command))
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ class Worker:
|
|||||||
return search_objects
|
return search_objects
|
||||||
|
|
||||||
def first_run(self, product):
|
def first_run(self, product):
|
||||||
logging.info(f"First run for {product['product_name']} for {walladb.get_user(product['telegram_user_id'])} ({walladb.get_user(product['telegram_user_id'])})")
|
for _ in range(10):
|
||||||
for i in range(5):
|
|
||||||
helpers.random_wait()
|
helpers.random_wait()
|
||||||
|
logging.info(f"First run for {product['product_name']} for {walladb.get_user(product['telegram_user_id'])} ({walladb.get_user(product['telegram_user_id'])})")
|
||||||
list = []
|
list = []
|
||||||
if not helpers.is_valid_request(product):
|
if not helpers.is_valid_request(product):
|
||||||
return list
|
return list
|
||||||
@@ -95,7 +95,7 @@ class Worker:
|
|||||||
return list
|
return list
|
||||||
|
|
||||||
async def work(self, product, list):
|
async def work(self, product, list):
|
||||||
helpers.random_wait() # Random wait to make requests separated in time in order to prevent API rate limit
|
await helpers.random_async_wait() # Random wait to make requests separated in time in order to prevent API rate limit
|
||||||
exec_times = []
|
exec_times = []
|
||||||
while True:
|
while True:
|
||||||
#logging.info(f"List for {product['product_name']} length is: {len(list)}")
|
#logging.info(f"List for {product['product_name']} length is: {len(list)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user