diff --git a/wiki_pages/FilmsByReference.py b/wiki_pages/FilmsByReference.py index b3e5964..9cfd8bc 100644 --- a/wiki_pages/FilmsByReference.py +++ b/wiki_pages/FilmsByReference.py @@ -1,7 +1,6 @@ from collections import OrderedDict -import string +import wikipedia -from bookstack import Bookstack from vcinema_utils import VCinemaUtils # Page ID of https://wiki.jacknet.io/books/vcinema/page/references @@ -25,12 +24,32 @@ def build_page(films_by_reference_keyword): table = "| Referenced | Films |\n| - | - |" - for year in reference_keywords_sorted.keys(): + for reference_keyword in reference_keywords_sorted.keys(): table += "\n" row_data = [] - row_data.append("[{}](https://en.wikipedia.org/wiki/{})".format(str(string.capwords(year[13:].replace("-", " "))), str(string.capwords(year[13:].replace("-", " ")).replace(" ", "_")))) - row_data.append(VCinemaUtils.get_film_list(reference_keywords_sorted[year])) + + referenced = reference_keyword[13:].replace("-", " ") + + if referenced.startswith("a "): + referenced = referenced[2:] + else: + referenced = referenced + + try: + searches = wikipedia.search(referenced, suggestion=False) + referenced_page = wikipedia.page(title=referenced, auto_suggest=False) + row_data.append("[{}]({}) ()".format(referenced_page.title, referenced_page.url, reference_keyword)) + except wikipedia.DisambiguationError as e1: + row_data.append("[{}](https://en.wikipedia.org/wiki/{})) ()".format(e1.title, e1.title.replace(" ", "_"), reference_keyword)) + except wikipedia.PageError as _: + try: + referenced_page = wikipedia.page(title=searches[0], auto_suggest=False) + row_data.append("[{}]({}) ()".format(referenced_page.title, referenced_page.url, reference_keyword)) + except wikipedia.DisambiguationError as e2: + row_data.append( + "[{}](https://en.wikipedia.org/wiki/{})) ()".format(e2.title, e2.title.replace(" ", "_"),reference_keyword)) + row_data.append(VCinemaUtils.get_film_list(reference_keywords_sorted[reference_keyword])) table += " | ".join(row_data)