Skip to content

Commit

Permalink
need title for fresh products
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Sep 15, 2024
1 parent 83790e1 commit 3c482a7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions say/crawler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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']

Expand Down

0 comments on commit 3c482a7

Please sign in to comment.