Skip to content

Commit

Permalink
Handle several offers when claiming product
Browse files Browse the repository at this point in the history
Sometimes they are several offers in the offer_response. We just get the last updated one.
  • Loading branch information
laurentlemercier authored and mjenczmyk committed Jun 8, 2020
1 parent b22b1c1 commit 2f1e19d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/claimer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime as dt
from itertools import chain
from math import ceil
from operator import itemgetter

from api import (
DEFAULT_PAGINATION_SIZE,
Expand Down Expand Up @@ -68,7 +69,9 @@ def claim_product(api_client, recaptcha_solution):
logger.info("There is no Free Learning offer right now")
raise Exception("There is no Free Learning offer right now")

[offer_data] = offer_response.json().get('data')
# Sometimes they are several offers. We just get the last updated one.
offer_data = max(offer_response.json().get('data'), key=itemgetter('updatedAt'))

offer_id = offer_data.get('id')
product_id = offer_data.get('productId')

Expand Down

0 comments on commit 2f1e19d

Please sign in to comment.