Fix: bot not notifying new articles + minor refactor
This commit is contained in:
71
datalayer/item_monitor.py
Normal file
71
datalayer/item_monitor.py
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
class ItemMonitor:
|
||||
def __init__(self, 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):
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def load_from_json(cls, json_data):
|
||||
return cls(
|
||||
json_data['search_query'],
|
||||
json_data['latitude'],
|
||||
json_data['longitude'],
|
||||
json_data['max_distance'],
|
||||
json_data['condition'],
|
||||
json_data['min_price'],
|
||||
json_data['max_price'],
|
||||
json_data['title_exclude'],
|
||||
json_data['description_exclude'],
|
||||
json_data['title_must_include'],
|
||||
json_data['description_must_include'],
|
||||
json_data['title_first_word_exclude']
|
||||
)
|
||||
|
||||
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
|
||||
55
datalayer/wallapop_article.py
Normal file
55
datalayer/wallapop_article.py
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
class WallapopArticle:
|
||||
def __init__(self, id, title, description, price, currency, location, allows_shipping, url):
|
||||
self._id = id
|
||||
self._title = title
|
||||
self._description = description
|
||||
self._price = price
|
||||
self._currency = currency
|
||||
self._location = location
|
||||
self._allows_shipping = allows_shipping
|
||||
self._url = url
|
||||
|
||||
@classmethod
|
||||
def load_from_json(cls, json_data):
|
||||
return cls(
|
||||
json_data['id'],
|
||||
json_data['title'],
|
||||
json_data['description'],
|
||||
json_data['price'],
|
||||
json_data['currency'],
|
||||
json_data['location']['city'],
|
||||
json_data['shipping']['user_allows_shipping'],
|
||||
json_data['web_slug']
|
||||
)
|
||||
|
||||
def get_id(self):
|
||||
return self._id
|
||||
|
||||
def get_title(self):
|
||||
return self._title
|
||||
|
||||
def get_description(self):
|
||||
return self._description
|
||||
|
||||
def get_price(self):
|
||||
return self._price
|
||||
|
||||
def get_currency(self):
|
||||
return self._currency
|
||||
|
||||
def get_location(self):
|
||||
return self._location
|
||||
|
||||
def get_allows_shipping(self):
|
||||
return self._allows_shipping
|
||||
|
||||
def get_url(self):
|
||||
return self._url
|
||||
|
||||
def __eq__(self, article):
|
||||
return self.get_id() == article.get_id()
|
||||
|
||||
def __str__(self):
|
||||
return f"Article(id={self._id}, title='{self._title}', " \
|
||||
f"price={self._price} {self._currency}, url='{self._url}')"
|
||||
Reference in New Issue
Block a user