99 lines
3.3 KiB
Python
99 lines
3.3 KiB
Python
|
|
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):
|
|
self._name = name
|
|
self._search_query = search_query
|
|
self._latitude = latitude
|
|
self._longitude = longitude
|
|
self._max_distance = max_distance
|
|
self._condition = condition
|
|
self._min_price = min_price
|
|
self._max_price = max_price
|
|
self._title_exclude = title_exclude
|
|
self._description_exclude = description_exclude
|
|
self._title_must_include = title_must_include
|
|
self._description_must_include = description_must_include
|
|
self._title_first_word_exclude = title_first_word_exclude
|
|
self._check_every = check_every
|
|
self._thread_id = thread_id
|
|
self._platform = platform
|
|
self._country = country
|
|
@classmethod
|
|
def load_from_json(cls, json_data):
|
|
# search_query is mandatory
|
|
if 'search_query' not in json_data:
|
|
raise ValueError("Missing mandatory field: search_query")
|
|
|
|
return cls(
|
|
json_data['name'],
|
|
json_data['search_query'],
|
|
json_data.get('latitude', 0),
|
|
json_data.get('longitude', 0),
|
|
json_data.get('max_distance', 0),
|
|
json_data.get('condition', 'all'),
|
|
json_data.get('min_price', 0),
|
|
json_data.get('max_price', 0),
|
|
json_data.get('title_exclude', []),
|
|
json_data.get('description_exclude', []),
|
|
json_data.get('title_must_include', []),
|
|
json_data.get('description_must_include', []),
|
|
json_data.get('title_first_word_exclude', []),
|
|
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.)
|
|
)
|
|
|
|
def get_name(self):
|
|
return self._name
|
|
|
|
def get_search_query(self):
|
|
return self._search_query
|
|
|
|
def get_latitude(self):
|
|
return self._latitude
|
|
|
|
def get_longitude(self):
|
|
return self._longitude
|
|
|
|
def get_max_distance(self):
|
|
return self._max_distance
|
|
|
|
def get_condition(self):
|
|
return self._condition
|
|
|
|
def get_min_price(self):
|
|
return self._min_price
|
|
|
|
def get_max_price(self):
|
|
return self._max_price
|
|
|
|
def get_title_exclude(self):
|
|
return self._title_exclude
|
|
|
|
def get_description_exclude(self):
|
|
return self._description_exclude
|
|
|
|
def get_title_must_include(self):
|
|
return self._title_must_include
|
|
|
|
def get_description_must_include(self):
|
|
return self._description_must_include
|
|
|
|
def get_title_first_word_exclude(self):
|
|
return self._title_first_word_exclude
|
|
|
|
def get_check_every(self):
|
|
return self._check_every
|
|
|
|
def get_thread_id(self):
|
|
return self._thread_id
|
|
|
|
def get_platform(self):
|
|
return self._platform
|
|
|
|
def get_country(self):
|
|
return self._country |