From 3c482a7131dc3b77096f1b7a8e9539278807d9c5 Mon Sep 17 00:00:00 2001 From: ehsang Date: Sun, 15 Sep 2024 14:20:22 +0330 Subject: [PATCH] need title for fresh products --- say/crawler/__init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/say/crawler/__init__.py b/say/crawler/__init__.py index 4922c5f6..0840c386 100644 --- a/say/crawler/__init__.py +++ b/say/crawler/__init__.py @@ -105,7 +105,8 @@ def get_data(self, force=False): class DigikalaCrawler: - API_URL = 'https://api.digikala.com/v2/product/%s/' + API_URL_NOT_FRESH = 'https://api.digikala.com/v2/product/%s/' + API_URL_FRESH = 'https://api-fresh.digikala.com/v1/product/%s/' DKP_PATTERN = re.compile(r'.*/dkp-(\d+).*') def __init__(self, url): @@ -117,15 +118,23 @@ def __init__(self, url): def get_data(self, force=False): if self.dkp is None: return - - url = self.API_URL % self.dkp + + url = self.API_URL_NOT_FRESH % self.dkp if force: r = requests.get(url) else: r = request_with_cache(url) if r.status_code != 200: - return + # fresh products have different api + url = self.API_URL_FRESH % self.dkp + if force: + r = requests.get(url) + else: + r = request_with_cache(url) + + if r.status_code != 200: + return data = r.json()['data']