utils: Add force option to always hit endpoint.

This commit is contained in:
Vishnu KS
2019-10-12 17:10:07 +05:30
parent c619ae91f6
commit 08b11eb478
2 changed files with 11 additions and 3 deletions

View File

@@ -19,12 +19,13 @@ def get_details(book_object):
book_object['lang'] = book.find('language_code').text
book_object['rating'] = book.find('average_rating').text
book_object['pages'] = book.find('num_pages').text
book_object['image_url'] = book.find('image_url').text
except urllib.error.HTTPError as e:
print('Error getting book details from GoodReads for book: {}. \nGot error: '.format(book_object['title']))
print(str(e.getcode()) + ' ' + e.msg)
def get_goodread_info(library):
def get_goodread_info(library, force):
import sys
print('')
print('Getting GoodReads data...')
@@ -39,7 +40,7 @@ def get_goodread_info(library):
book_list = library[chapter]
for book in book_list:
# do not call the api again if we already have the infomation
if 'rating' in book and book['rating']:
if not force and 'rating' in book and book['rating']:
processed += 1
continue
get_details(book)