Skip to content

Commit 553fa3d

Browse files
committed
Handle empty Language and/or Title 🐛
1 parent 08edaba commit 553fa3d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pythonbits/goodreads.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ def _extract_author(auth):
4141

4242

4343
def _extract_language(alpha_3):
44+
if not alpha_3:
45+
return _read_language()
4446
try:
4547
return pycountry.languages.get(alpha_3=alpha_3).name
4648
except AttributeError:
4749
try:
4850
return pycountry.languages.get(alpha_2=alpha_3[:2]).name
4951
except AttributeError:
5052
# I give up
51-
return input('Please specify the book\'s Language: ')
53+
return _read_language()
54+
55+
56+
def _read_language():
57+
return input('Please specify the book\'s Language: ')
5258

5359

5460
def _extract_shelves(shelves, take):
@@ -104,7 +110,7 @@ def search(self, path):
104110

105111
if isbn:
106112
log.debug("Searching Goodreads by ISBN {} for '{}'",
107-
isbn, book['Title'])
113+
isbn, book.get('Title', isbn))
108114
return self.show_by_isbn(isbn)
109115
elif book['Title']:
110116
search_term = book['Title']

pythonbits/openlibrary.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
"""
55
Note, read https://openlibrary.org/dev/docs/api/covers
6-
The cover access by ids other than CoverID and OLID are rate-limited.
6+
The cover access by ids other than CoverID and OLID are rate-limited.
77
Currently only 100 requests/IP are allowed for every 5 minutes.
8-
If any IP tries to access more that the allowed limit,
8+
If any IP tries to access more that the allowed limit,
99
the service will return "403 Forbidden" status.
1010
"""
1111

12-
from .logging import log
13-
1412
API_URL = 'http://covers.openlibrary.org/b/{}/{}-{}.jpg'
1513

1614

0 commit comments

Comments
 (0)