get references before generating table
This commit is contained in:
parent
e89eb33230
commit
9de7ec31c2
|
@ -1,6 +1,7 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import wikipedia
|
import wikipedia
|
||||||
|
|
||||||
|
from bookstack import Bookstack
|
||||||
from vcinema_utils import VCinemaUtils
|
from vcinema_utils import VCinemaUtils
|
||||||
|
|
||||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/references
|
# Page ID of https://wiki.jacknet.io/books/vcinema/page/references
|
||||||
|
@ -20,14 +21,11 @@ def update_page(token_id, token_secret, films_by_reference_keyword):
|
||||||
|
|
||||||
|
|
||||||
def build_page(films_by_reference_keyword):
|
def build_page(films_by_reference_keyword):
|
||||||
reference_keywords_sorted = OrderedDict(sorted(films_by_reference_keyword.items(), key=lambda t: t[0]))
|
references = {}
|
||||||
|
|
||||||
table = "| Referenced | Films |\n| - | - |"
|
for reference_keyword in films_by_reference_keyword:
|
||||||
|
|
||||||
for reference_keyword in reference_keywords_sorted.keys():
|
print(reference_keyword)
|
||||||
table += "\n"
|
|
||||||
|
|
||||||
row_data = []
|
|
||||||
|
|
||||||
referenced = reference_keyword[13:].replace("-", " ")
|
referenced = reference_keyword[13:].replace("-", " ")
|
||||||
|
|
||||||
|
@ -39,17 +37,44 @@ def build_page(films_by_reference_keyword):
|
||||||
try:
|
try:
|
||||||
searches = wikipedia.search(referenced, suggestion=False)
|
searches = wikipedia.search(referenced, suggestion=False)
|
||||||
referenced_page = wikipedia.page(title=referenced, auto_suggest=False)
|
referenced_page = wikipedia.page(title=referenced, auto_suggest=False)
|
||||||
row_data.append("[{}]({}) ()".format(referenced_page.title, referenced_page.url, reference_keyword))
|
|
||||||
|
page_title = referenced_page.title
|
||||||
|
page_url = referenced_page.url
|
||||||
|
|
||||||
except wikipedia.DisambiguationError as e1:
|
except wikipedia.DisambiguationError as e1:
|
||||||
row_data.append("[{}](https://en.wikipedia.org/wiki/{})) ()".format(e1.title, e1.title.replace(" ", "_"), reference_keyword))
|
page_title = e1.title
|
||||||
|
page_url = "https://en.wikipedia.org/wiki/{}".format(e1.title.replace(" ", "_"))
|
||||||
except wikipedia.PageError as _:
|
except wikipedia.PageError as _:
|
||||||
try:
|
try:
|
||||||
referenced_page = wikipedia.page(title=searches[0], auto_suggest=False)
|
referenced_page = wikipedia.page(title=searches[0], auto_suggest=False)
|
||||||
row_data.append("[{}]({}) ()".format(referenced_page.title, referenced_page.url, reference_keyword))
|
|
||||||
|
page_title = referenced_page.title
|
||||||
|
page_url = referenced_page.url
|
||||||
except wikipedia.DisambiguationError as e2:
|
except wikipedia.DisambiguationError as e2:
|
||||||
row_data.append(
|
page_title = e2.title
|
||||||
"[{}](https://en.wikipedia.org/wiki/{})) ()".format(e2.title, e2.title.replace(" ", "_"),reference_keyword))
|
page_url = "https://en.wikipedia.org/wiki/{}".format(e2.title.replace(" ", "_"))
|
||||||
row_data.append(VCinemaUtils.get_film_list(reference_keywords_sorted[reference_keyword]))
|
|
||||||
|
if page_title in references.keys():
|
||||||
|
references[page_title]["films"].extend(films_by_reference_keyword[reference_keyword])
|
||||||
|
else:
|
||||||
|
references[page_title] = {"url": page_url,
|
||||||
|
"films": films_by_reference_keyword[reference_keyword]}
|
||||||
|
|
||||||
|
references_sorted = OrderedDict(sorted(references.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
|
table = "| Referenced | Films |\n| - | - |"
|
||||||
|
|
||||||
|
for reference, referenced in references_sorted.items():
|
||||||
|
table += "\n"
|
||||||
|
|
||||||
|
row_data = []
|
||||||
|
|
||||||
|
reference_url = referenced["url"]
|
||||||
|
reference_title = reference
|
||||||
|
referenced_films = referenced["films"]
|
||||||
|
|
||||||
|
row_data.append("[{}]({})".format(reference_title, reference_url))
|
||||||
|
row_data.append(VCinemaUtils.get_film_list(referenced_films))
|
||||||
|
|
||||||
table += " | ".join(row_data)
|
table += " | ".join(row_data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue