62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import datetime
|
|
|
|
class Article:
|
|
"""Generic article model for any marketplace platform"""
|
|
|
|
def __init__(self, id, title, description, price, currency, location,
|
|
allows_shipping, url, images, modified_at, platform):
|
|
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
|
|
self._platform = platform
|
|
|
|
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 self._images
|
|
|
|
def get_modified_at(self):
|
|
return self._modified_at
|
|
|
|
def get_platform(self):
|
|
return self._platform
|
|
|
|
def __eq__(self, article):
|
|
# Two articles are equal if they have the same ID and platform
|
|
return self.get_id() == article.get_id() and self.get_platform() == article.get_platform()
|
|
|
|
def __str__(self):
|
|
return f"Article(platform={self._platform}, id={self._id}, title='{self._title}', " \
|
|
f"price={self._price} {self._currency}, url='{self._url}', modified_at='{self._modified_at}')"
|
|
|