use page of wikipedia page for table row

This commit is contained in:
Sarah 2022-12-03 12:05:52 +00:00
parent 35d3637cd9
commit e89eb33230
1 changed files with 24 additions and 5 deletions

View File

@ -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)