mongodb
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import uuid
|
||||
|
||||
class ItemMonitor:
|
||||
def __init__(self, name, search_query, latitude, longitude, max_distance,
|
||||
condition, min_price, max_price, title_exclude,
|
||||
description_exclude, title_must_include, description_must_include,
|
||||
title_first_word_exclude, check_every, thread_id, platform, country):
|
||||
title_first_word_exclude, check_every, thread_id, platform, country, worker_id=None):
|
||||
self._worker_id = worker_id if worker_id else str(uuid.uuid4())
|
||||
self._name = name
|
||||
self._search_query = search_query
|
||||
self._latitude = latitude
|
||||
@@ -27,6 +29,11 @@ class ItemMonitor:
|
||||
if 'search_query' not in json_data:
|
||||
raise ValueError("Missing mandatory field: search_query")
|
||||
|
||||
# Generar ID si no existe (para compatibilidad con workers antiguos)
|
||||
worker_id = json_data.get('id') or json_data.get('worker_id')
|
||||
if not worker_id:
|
||||
worker_id = str(uuid.uuid4())
|
||||
|
||||
return cls(
|
||||
json_data['name'],
|
||||
json_data['search_query'],
|
||||
@@ -44,9 +51,13 @@ class ItemMonitor:
|
||||
json_data.get('check_every', 30),
|
||||
json_data.get('thread_id', 1),
|
||||
json_data.get('platform', 'wallapop'), # Default to wallapop for backward compatibility
|
||||
json_data.get('country', 'es') # Default country for platforms that support it (Vinted, etc.)
|
||||
json_data.get('country', 'es'), # Default country for platforms that support it (Vinted, etc.)
|
||||
worker_id
|
||||
)
|
||||
|
||||
def get_id(self):
|
||||
return self._worker_id
|
||||
|
||||
def get_name(self):
|
||||
return self._name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user