Skip to content

Commit dad3a67

Browse files
committed
handle index error in case Thoth returns result of books with no chapters defined
1 parent 39b7cfc commit dad3a67

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

cit-ex/obp-loader.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ def main():
3939
chapters = get_chapters(query)
4040

4141
# add bibliography section (if any) to chapter list
42-
bib_url = urljoin(chapters[0].get("html_page"), "bibliography.xhtml")
43-
r = requests.get(bib_url)
44-
if r.status_code == 200:
45-
chapters.append({"doi": args.doi, "html_page": bib_url})
42+
try:
43+
bib_url = urljoin(chapters[0].get("html_page"), "bibliography.xhtml")
44+
except IndexError:
45+
pass
46+
else:
47+
r = requests.get(bib_url)
48+
if r.status_code == 200:
49+
chapters.append({"doi": args.doi, "html_page": bib_url})
4650

4751
# create an epub for each chapter and run it through cit-ex
4852
for chapter in chapters:

0 commit comments

Comments
 (0)