feat: default values, general item excludes, images, queueManager to manage multi worker messaging to telegram to prevent too many connections
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import datetime
|
||||
import pandas as pd
|
||||
|
||||
class WallapopArticle:
|
||||
def __init__(self, id, title, description, price, currency, location, allows_shipping, url):
|
||||
def __init__(self, id, title, description, price, currency, location, allows_shipping, url, images, modified_at):
|
||||
self._id = id
|
||||
self._title = title
|
||||
self._description = description
|
||||
@@ -9,7 +11,8 @@ class WallapopArticle:
|
||||
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(
|
||||
@@ -20,7 +23,9 @@ class WallapopArticle:
|
||||
json_data['price']['currency'],
|
||||
json_data['location']['city'],
|
||||
json_data['shipping']['user_allows_shipping'],
|
||||
json_data['web_slug']
|
||||
json_data['web_slug'],
|
||||
json_data['images'],
|
||||
json_data['modified_at']
|
||||
)
|
||||
|
||||
def get_id(self):
|
||||
@@ -30,7 +35,8 @@ class WallapopArticle:
|
||||
return self._title
|
||||
|
||||
def get_description(self):
|
||||
return self._description
|
||||
#return only 500 characters
|
||||
return self._description[:500] + "..." if len(self._description) > 500 else self._description
|
||||
|
||||
def get_price(self):
|
||||
return self._price
|
||||
@@ -42,14 +48,23 @@ class WallapopArticle:
|
||||
return self._location
|
||||
|
||||
def get_allows_shipping(self):
|
||||
return self._allows_shipping
|
||||
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}')"
|
||||
f"price={self._price} {self._currency}, url='{self._url}', modified_at='{self._modified_at}')"
|
||||
Reference in New Issue
Block a user