Skip to content

Commit

Permalink
Recover precheck logic to prevent reclaim (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m3vilurr authored and mjenczmyk committed Apr 30, 2019
1 parent ea345df commit abb191a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/packtPublishingFreeEbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,19 @@ def grab_ebook(self, api_client):
[user_data] = user_response.json().get('data')
user_id = user_data.get('id')

product_response = api_client.get(PACKT_PRODUCT_SUMMARY_URL.format(product_id=product_id))
self.book_data = {'id': product_id, 'title': product_response.json()['title']}\
if product_response.status_code == 200 else None

if any(product_id == book['id'] for book in self.get_all_books_data(api_client)):
logger.info('You have already claimed Packt Free Learning "{}" offer.'.format(self.book_data['title']))
return

claim_response = api_client.put(
PACKT_API_FREE_LEARNING_CLAIM_URL.format(user_id=user_id, offer_id=offer_id),
json={'recaptcha': self.solve_packt_recapcha()}
)

product_response = api_client.get(PACKT_PRODUCT_SUMMARY_URL.format(product_id=product_id))
self.book_data = {'id': product_id, 'title': product_response.json()['title']}\
if product_response.status_code == 200 else None

if claim_response.status_code == 200:
logger.info('A new Packt Free Learning ebook "{}" has been grabbed!'.format(self.book_data['title']))
elif claim_response.status_code == 409:
Expand Down

0 comments on commit abb191a

Please sign in to comment.