add abstraction ob platform and article + vinted
" Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
|
||||
class ItemMonitor:
|
||||
def __init__(self, name,search_query, latitude, longitude, max_distance,
|
||||
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):
|
||||
title_first_word_exclude, check_every, thread_id, platform, country):
|
||||
self._name = name
|
||||
self._search_query = search_query
|
||||
self._latitude = latitude
|
||||
@@ -19,6 +19,8 @@ class ItemMonitor:
|
||||
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
|
||||
@@ -40,7 +42,9 @@ class ItemMonitor:
|
||||
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('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):
|
||||
@@ -86,4 +90,10 @@ class ItemMonitor:
|
||||
return self._check_every
|
||||
|
||||
def get_thread_id(self):
|
||||
return self._thread_id
|
||||
return self._thread_id
|
||||
|
||||
def get_platform(self):
|
||||
return self._platform
|
||||
|
||||
def get_country(self):
|
||||
return self._country
|
||||
@@ -1,70 +0,0 @@
|
||||
import datetime
|
||||
import pandas as pd
|
||||
|
||||
class WallapopArticle:
|
||||
def __init__(self, id, title, description, price, currency, location, allows_shipping, url, images, modified_at):
|
||||
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
|
||||
self._images = images
|
||||
self._modified_at = modified_at
|
||||
@classmethod
|
||||
def load_from_json(cls, json_data):
|
||||
return cls(
|
||||
json_data['id'],
|
||||
json_data['title'],
|
||||
json_data['description'],
|
||||
json_data['price']['amount'],
|
||||
json_data['price']['currency'],
|
||||
json_data['location']['city'],
|
||||
json_data['shipping']['user_allows_shipping'],
|
||||
json_data['web_slug'],
|
||||
json_data['images'],
|
||||
json_data['modified_at']
|
||||
)
|
||||
|
||||
def get_id(self):
|
||||
return self._id
|
||||
|
||||
def get_title(self):
|
||||
return self._title
|
||||
|
||||
def get_description(self):
|
||||
#return only 500 characters
|
||||
return self._description[:500] + "..." if len(self._description) > 500 else 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 "✅" if self._allows_shipping else "❌"
|
||||
|
||||
def get_url(self):
|
||||
return self._url
|
||||
|
||||
def get_images(self):
|
||||
return [img['urls']['medium'] for img in self._images[:3]]
|
||||
|
||||
def get_modified_at(self):
|
||||
# Convert timestamp in milliseconds to datetime string "YYYY-MM-DD HH:MM:SS"
|
||||
ts = int(self._modified_at)
|
||||
dt = datetime.date.fromtimestamp(ts / 1000)
|
||||
return dt.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
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}', modified_at='{self._modified_at}')"
|
||||
Reference in New Issue
Block a user