utils: Add force option to always hit endpoint.
This commit is contained in:
@@ -19,12 +19,13 @@ def get_details(book_object):
|
|||||||
book_object['lang'] = book.find('language_code').text
|
book_object['lang'] = book.find('language_code').text
|
||||||
book_object['rating'] = book.find('average_rating').text
|
book_object['rating'] = book.find('average_rating').text
|
||||||
book_object['pages'] = book.find('num_pages').text
|
book_object['pages'] = book.find('num_pages').text
|
||||||
|
book_object['image_url'] = book.find('image_url').text
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
print('Error getting book details from GoodReads for book: {}. \nGot error: '.format(book_object['title']))
|
print('Error getting book details from GoodReads for book: {}. \nGot error: '.format(book_object['title']))
|
||||||
print(str(e.getcode()) + ' ' + e.msg)
|
print(str(e.getcode()) + ' ' + e.msg)
|
||||||
|
|
||||||
|
|
||||||
def get_goodread_info(library):
|
def get_goodread_info(library, force):
|
||||||
import sys
|
import sys
|
||||||
print('')
|
print('')
|
||||||
print('Getting GoodReads data...')
|
print('Getting GoodReads data...')
|
||||||
@@ -39,7 +40,7 @@ def get_goodread_info(library):
|
|||||||
book_list = library[chapter]
|
book_list = library[chapter]
|
||||||
for book in book_list:
|
for book in book_list:
|
||||||
# do not call the api again if we already have the infomation
|
# 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
|
processed += 1
|
||||||
continue
|
continue
|
||||||
get_details(book)
|
get_details(book)
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ try:
|
|||||||
'--sort_by',
|
'--sort_by',
|
||||||
choices = ['rating', 'title', 'author', 'year'],
|
choices = ['rating', 'title', 'author', 'year'],
|
||||||
help='defaults to rating')
|
help='defaults to rating')
|
||||||
|
parser.add_argument(
|
||||||
|
'--force',
|
||||||
|
dest='force',
|
||||||
|
action='store_true',
|
||||||
|
default=False
|
||||||
|
)
|
||||||
flags = parser.parse_args()
|
flags = parser.parse_args()
|
||||||
except ImportError:
|
except ImportError:
|
||||||
flags = None
|
flags = None
|
||||||
@@ -42,10 +48,11 @@ def main():
|
|||||||
out_file = flags.out_file or './../README-new.md'
|
out_file = flags.out_file or './../README-new.md'
|
||||||
input_file_type = flags.input_file_type or 'new'
|
input_file_type = flags.input_file_type or 'new'
|
||||||
sort_by = flags.sort_by or 'rating'
|
sort_by = flags.sort_by or 'rating'
|
||||||
|
force = flags.force
|
||||||
reverse = True if sort_by == 'rating' else False
|
reverse = True if sort_by == 'rating' else False
|
||||||
|
|
||||||
library = load(in_file, input_file_type)
|
library = load(in_file, input_file_type)
|
||||||
get_goodread_info(library)
|
get_goodread_info(library, force)
|
||||||
library = sort(library, sort_by, reverse)
|
library = sort(library, sort_by, reverse)
|
||||||
render(in_file, out_file, library)
|
render(in_file, out_file, library)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user