fix bug where script throws exception if no page exists for a reference keyword

This commit is contained in:
Sarah 2022-12-16 22:06:25 +00:00
parent 6baab1e287
commit daf93c2d45
1 changed files with 16 additions and 9 deletions

View File

@ -43,6 +43,7 @@ def get_films_by_reference(viewings):
page_title = page_title[0].upper() + page_title[1:]
page_url = VCinemaUtils.generate_wikipedia_url(page_title)
except wikipedia.PageError as _:
if len(searches) > 0:
try:
referenced_page = wikipedia.page(title=searches[0], auto_suggest=False)
@ -52,6 +53,9 @@ def get_films_by_reference(viewings):
page_title = e.title
page_title = page_title[0].upper() + page_title[1:]
page_url = VCinemaUtils.generate_wikipedia_url(page_title)
else:
page_title = referenced.title()
page_url = None
if page_title in films_by_reference.keys():
films_by_reference[page_title]["keywords"].append(keyword)
@ -85,6 +89,9 @@ def build_page(films_by_reference):
reference_url = referenced["url"]
referenced_films = referenced["films"]
if reference_url is None:
row_data.append(reference)
else:
row_data.append(VCinemaUtils.generate_markdown_link(reference, reference_url))
row_data.append(VCinemaUtils.get_film_list(referenced_films))