Skip to content

Commit

Permalink
Handle empty Language and/or Title 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
znedw committed Oct 21, 2020
1 parent 08edaba commit e50e741
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pythonbits/goodreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ def _extract_author(auth):


def _extract_language(alpha_3):
if not alpha_3:
return _read_language()
try:
return pycountry.languages.get(alpha_3=alpha_3).name
except AttributeError:
try:
return pycountry.languages.get(alpha_2=alpha_3[:2]).name
except AttributeError:
# I give up
return input('Please specify the book\'s Language: ')
return _read_language()


def _read_language():
return input('Please specify the book\'s Language: ')


def _extract_shelves(shelves, take):
Expand Down Expand Up @@ -104,7 +110,7 @@ def search(self, path):

if isbn:
log.debug("Searching Goodreads by ISBN {} for '{}'",
isbn, book['Title'])
isbn, book.get('Title', isbn))
return self.show_by_isbn(isbn)
elif book['Title']:
search_term = book['Title']
Expand Down

0 comments on commit e50e741

Please sign in to comment.