Skip to content

Commit

Permalink
fresh product changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Sep 15, 2024
1 parent a0f9ab8 commit 1c11ab7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
10 changes: 8 additions & 2 deletions say/api/need_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ def patch(self, need_id):

need.link = new_link
session.flush()
update_need.delay(need.id, force=True)
if "Protein" in self.name_translations.en | "Dairy" in self.name_translations.en:
update_need.delay(need.id, True)
else:
update_need.delay(need.id, False)

if 'affiliateLinkUrl' in request.form.keys():
need.affiliateLinkUrl = request.form['affiliateLinkUrl']
Expand Down Expand Up @@ -691,8 +694,11 @@ def post(self):

if new_need.link:
from say.tasks import update_need
if "Protein" in name_translations.en | "Dairy" in name_translations.en:
update_need.delay(new_need.id, True)
else:
update_need.delay(new_need.id, False)

update_need.delay(new_need.id)

return new_need

Expand Down
22 changes: 12 additions & 10 deletions say/crawler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,26 @@ def __init__(self, url):
except IndexError:
self.dkp = None

def get_data(self, force=False):
def get_data(self, fresh, force=False):
if self.dkp is None:
return

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:
# fresh products have different api
# fresh products have different api
if fresh:
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
else:
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

Expand Down
4 changes: 2 additions & 2 deletions say/models/need_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ def current_participants(self):
paid=past_participation.paid,
)

def update(self, force=False):
def update(self, fresh, force=False):
from say.crawler import Crawler
from say.crawler import DigikalaCrawler

if 'digikala' in self.link:
data = DigikalaCrawler(self.link).get_data(force=force)
data = DigikalaCrawler(self.link).get_data(fresh, force=force)
else:
data = Crawler(self.link).get_data(force=force)

Expand Down
4 changes: 2 additions & 2 deletions say/tasks/update_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def update_needs(self):
retry_kwargs={'max_retries': 1},
queue='slow',
)
def update_need(self, need_id, force=False):
def update_need(self, need_id, fresh, force=False):
from say.models.need_model import Need

sleep(5)
need = self.session.query(Need).get(need_id)
data = need.update(force=force)
data = need.update(fresh, force=force)
safe_commit(self.session)

return data

0 comments on commit 1c11ab7

Please sign in to comment.