Changed list of articles to dictionary, there was a mem leak there
This commit is contained in:
@@ -61,24 +61,24 @@ class Worker:
|
||||
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 i in range(5):
|
||||
helpers.random_wait()
|
||||
list = []
|
||||
list = {}
|
||||
if not helpers.is_valid_request(product):
|
||||
return list
|
||||
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'])
|
||||
for article in articles:
|
||||
list.insert(0, article['id'])
|
||||
list[article['id']] = 1
|
||||
else:
|
||||
if '0' in product['category'].split(','):
|
||||
articles = self.request(product['product_name'], 0, product['latitude'], product['longitude'], product['distance'], product['condition'], product['min_price'], product['max_price'])
|
||||
for article in articles:
|
||||
list.insert(0, article['id'])
|
||||
list[article['id']] = 1
|
||||
else:
|
||||
for category in product['category'].split(','):
|
||||
if product['subcategory'] == '' or not helpers.has_subcategory(category):
|
||||
articles = self.request(product['product_name'], 0, product['latitude'], product['longitude'], product['distance'], product['condition'], product['min_price'], product['max_price'], category)
|
||||
for article in articles:
|
||||
list.insert(0, article['id'])
|
||||
list[article['id']] = 1
|
||||
else:
|
||||
subcategories = []
|
||||
for subcategory in product['subcategory'].split(','):
|
||||
@@ -86,7 +86,7 @@ class Worker:
|
||||
subcategories.append(subcategory)
|
||||
articles = self.request(product['product_name'], 0, product['latitude'], product['longitude'], product['distance'], product['condition'], product['min_price'], product['max_price'], category, subcategories)
|
||||
for article in articles:
|
||||
list.insert(0, article['id'])
|
||||
list[article['id']] = 1
|
||||
return list
|
||||
|
||||
async def work(self, product, list):
|
||||
@@ -104,7 +104,7 @@ class Worker:
|
||||
if '0' in product['category'].split(','):
|
||||
articles = self.request(product['product_name'], 0, product['latitude'], product['longitude'], product['distance'], product['condition'], product['min_price'], product['max_price'])
|
||||
for article in articles:
|
||||
list.insert(0, article['id'])
|
||||
list[article['id']] = 1
|
||||
else:
|
||||
for category in product['category'].split(','):
|
||||
if product['subcategory'] == '' or not helpers.has_subcategory(category):
|
||||
@@ -127,7 +127,7 @@ class Worker:
|
||||
await helpers.send_article(article, product)
|
||||
await asyncio.sleep(1)
|
||||
#time.sleep(1) # Avoid Telegram flood restriction
|
||||
list.insert(0, article['id'])
|
||||
list[article['id']] = 1
|
||||
except Exception as e:
|
||||
logging.info("---------- EXCEPTION -----------")
|
||||
logging.info(f"{product['product_name']} worker crashed. {e}")
|
||||
|
||||
Reference in New Issue
Block a user