Fixed typo. Dont start not valid workers
This commit is contained in:
@@ -135,7 +135,7 @@ async def send_article(article, product):
|
|||||||
found_by = f"*🔍 Encontrado por la búsqueda de:* {telegram_escape_characters(product['product_name'])}"
|
found_by = f"*🔍 Encontrado por la búsqueda de:* {telegram_escape_characters(product['product_name'])}"
|
||||||
created_at = f"*📅 Fecha de publicación:* {telegram_escape_characters(get_publish_date(article))}"
|
created_at = f"*📅 Fecha de publicación:* {telegram_escape_characters(get_publish_date(article))}"
|
||||||
modified_at = f"*📅 Fecha de modificación:* {telegram_escape_characters(get_modified_date(article))}"
|
modified_at = f"*📅 Fecha de modificación:* {telegram_escape_characters(get_modified_date(article))}"
|
||||||
location = f"📍 *Lugar:* {telegram_escape_characters(article['location']['city'])} {telegram_escape_characters('(' + article['location']['postal_code']) + ')' } {telegram_escape_characters('- (' + article['location']['country_code']) + ')'}"
|
location = f"📍 *Lugar:* {telegram_escape_characters(article['location']['city'])} {telegram_escape_characters('(' + article['location']['postal_code'] + ')')} {telegram_escape_characters('- (' + article['location']['country_code'] + ')')}"
|
||||||
if article['shipping']['user_allows_shipping']:
|
if article['shipping']['user_allows_shipping']:
|
||||||
user_ships = f"📦 *Envío:* ✅"
|
user_ships = f"📦 *Envío:* ✅"
|
||||||
else:
|
else:
|
||||||
@@ -310,3 +310,12 @@ def send_to_nr(article, product):
|
|||||||
logging.error(f"Error sending to NR: {e}")
|
logging.error(f"Error sending to NR: {e}")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
|
def is_valid_request(product):
|
||||||
|
is_valid = False
|
||||||
|
if walladb.get_product(product):
|
||||||
|
if not walladb.is_user_expired(product['telegram_user_id']):
|
||||||
|
if walladb.is_user_valid(product['telegram_user_id']):
|
||||||
|
if walladb.is_user_premium(product['telegram_user_id']) or \
|
||||||
|
walladb.is_user_testing(product['telegram_user_id']):
|
||||||
|
is_valid = True
|
||||||
|
return is_valid
|
||||||
@@ -439,10 +439,11 @@ def main()->None:
|
|||||||
products = walladb.get_all_products()
|
products = walladb.get_all_products()
|
||||||
|
|
||||||
for product in products:
|
for product in products:
|
||||||
logging.info(product)
|
if helpers.is_valid_request(product):
|
||||||
p = threading.Thread(target=Worker.run, args=(product, ))
|
logging.info(product)
|
||||||
p.start()
|
p = threading.Thread(target=Worker.run, args=(product, ))
|
||||||
SEARCH_THREADS_LIST.append((product, p))
|
p.start()
|
||||||
|
SEARCH_THREADS_LIST.append((product, p))
|
||||||
|
|
||||||
"""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.
|
||||||
|
|||||||
@@ -17,16 +17,6 @@ class Worker:
|
|||||||
|
|
||||||
_stop = False
|
_stop = False
|
||||||
|
|
||||||
def is_valid_request(self, product):
|
|
||||||
is_valid = False
|
|
||||||
if walladb.get_product(product):
|
|
||||||
if not walladb.is_user_expired(product['telegram_user_id']):
|
|
||||||
if walladb.is_user_valid(product['telegram_user_id']):
|
|
||||||
if walladb.is_user_premium(product['telegram_user_id']) or \
|
|
||||||
walladb.is_user_testing(product['telegram_user_id']):
|
|
||||||
is_valid = True
|
|
||||||
return is_valid
|
|
||||||
|
|
||||||
def request(self, product_name, n_articles, latitude=constants.LATITUDE, longitude=constants.LONGITUDE, distance='0', condition='all', min_price=0, max_price=10000000, category="", subcategories=[]):
|
def request(self, product_name, n_articles, latitude=constants.LATITUDE, longitude=constants.LONGITUDE, distance='0', condition='all', min_price=0, max_price=10000000, category="", subcategories=[]):
|
||||||
distance = str(int(distance) * 1000)
|
distance = str(int(distance) * 1000)
|
||||||
url = (f"https://api.wallapop.com/api/v3/general/search?keywords={product_name}"
|
url = (f"https://api.wallapop.com/api/v3/general/search?keywords={product_name}"
|
||||||
@@ -72,7 +62,7 @@ class Worker:
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
helpers.random_wait()
|
helpers.random_wait()
|
||||||
list = []
|
list = []
|
||||||
if not self.is_valid_request(product):
|
if not helpers.is_valid_request(product):
|
||||||
return list
|
return list
|
||||||
if product['category'] == '':
|
if product['category'] == '':
|
||||||
articles = self.request(product['product_name'], 0, product['latitude'], product['longitude'], product['distance'], product['condition'], product['min_price'], product['max_price'], product['category'])
|
articles = self.request(product['product_name'], 0, product['latitude'], product['longitude'], product['distance'], product['condition'], product['min_price'], product['max_price'], product['category'])
|
||||||
@@ -103,7 +93,7 @@ class Worker:
|
|||||||
helpers.random_wait() # Random wait to make requests separated in time in order to prevent API rate limit
|
helpers.random_wait() # Random wait to make requests separated in time in order to prevent API rate limit
|
||||||
exec_times = []
|
exec_times = []
|
||||||
while True:
|
while True:
|
||||||
if not self.is_valid_request(product) or self._stop == True:
|
if not helpers.is_valid_request(product) or self._stop == True:
|
||||||
logging.info(f"{product['product_name']} not valid anymore, exiting worker")
|
logging.info(f"{product['product_name']} not valid anymore, exiting worker")
|
||||||
break # Exits and ends worker thread
|
break # Exits and ends worker thread
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user