Files
wallabicher/platforms/base_platform.py
Omar Sánchez Pizarro 4111f57564 add abstraction ob platform and article + vinted
"

Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
2025-10-10 14:58:27 +02:00

70 lines
1.7 KiB
Python

from abc import ABC, abstractmethod
class BasePlatform(ABC):
"""Abstract base class for marketplace platforms"""
def __init__(self, item_monitor):
"""
Initialize platform with item monitoring configuration
Args:
item_monitor: ItemMonitor instance with search parameters
"""
self._item_monitor = item_monitor
@abstractmethod
def get_platform_name(self):
"""
Get the name of the platform
Returns:
str: Platform name (e.g., 'wallapop', 'vinted', 'buyee')
"""
pass
@abstractmethod
def create_url(self):
"""
Create the search URL based on item_monitor parameters
Returns:
str: Complete URL for API/search request
"""
pass
@abstractmethod
def fetch_articles(self):
"""
Fetch articles from the platform
Returns:
list: List of Article objects
"""
pass
@abstractmethod
def parse_response(self, response_data):
"""
Parse platform-specific response into Article objects
Args:
response_data: Raw response data from the platform
Returns:
list: List of Article objects
"""
pass
def get_request_headers(self):
"""
Get platform-specific request headers
Override this method if platform needs custom headers
Returns:
dict: Headers for HTTP request
"""
return {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'
}