get references in the processing func

This commit is contained in:
Sarah 2022-12-04 13:00:58 +00:00
parent 9de7ec31c2
commit 95e7804a4a
1 changed files with 48 additions and 45 deletions

View File

@ -9,30 +9,22 @@ PAGE_ID = 62
def get_films_by_reference(viewings): def get_films_by_reference(viewings):
viewings_filtered_by_keyword = VCinemaUtils.filter_viewings(viewings, "keywords") films_by_reference = {}
viewings_filtered_by_reference_keyword = {k: v for k, v in viewings_filtered_by_keyword.items() if k.startswith("reference-to")}
return viewings_filtered_by_reference_keyword for viewing in viewings:
if "keywords" in viewing.keys():
for keyword in viewing["keywords"]:
if keyword.startswith("reference-to-"):
for reference in films_by_reference:
def update_page(token_id, token_secret, films_by_reference_keyword): if keyword in films_by_reference[reference]["keywords"]:
page = build_page(films_by_reference_keyword) films_by_reference[reference]["films"].append(viewing)
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID, markdown=page) break
else:
referenced = keyword[13:].replace("-", " ")
def build_page(films_by_reference_keyword):
references = {}
for reference_keyword in films_by_reference_keyword:
print(reference_keyword)
referenced = reference_keyword[13:].replace("-", " ")
if referenced.startswith("a "): if referenced.startswith("a "):
referenced = referenced[2:] referenced = referenced[2:]
else:
referenced = referenced
try: try:
searches = wikipedia.search(referenced, suggestion=False) searches = wikipedia.search(referenced, suggestion=False)
@ -54,17 +46,28 @@ def build_page(films_by_reference_keyword):
page_title = e2.title page_title = e2.title
page_url = "https://en.wikipedia.org/wiki/{}".format(e2.title.replace(" ", "_")) page_url = "https://en.wikipedia.org/wiki/{}".format(e2.title.replace(" ", "_"))
if page_title in references.keys(): if page_title in films_by_reference.keys():
references[page_title]["films"].extend(films_by_reference_keyword[reference_keyword]) films_by_reference[page_title]["films"].append(viewing)
films_by_reference[page_title]["keywords"].append(keyword)
else: else:
references[page_title] = {"url": page_url, films_by_reference[page_title] = {"url": page_url,
"films": films_by_reference_keyword[reference_keyword]} "keywords": [keyword],
"films": [viewing]}
references_sorted = OrderedDict(sorted(references.items(), key=lambda t: t[0])) return films_by_reference
def update_page(token_id, token_secret, films_by_reference_keyword):
page = build_page(films_by_reference_keyword)
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID, markdown=page)
def build_page(films_by_reference):
films_by_reference_sorted = OrderedDict(sorted(films_by_reference.items(), key=lambda t: t[0]))
table = "| Referenced | Films |\n| - | - |" table = "| Referenced | Films |\n| - | - |"
for reference, referenced in references_sorted.items(): for reference, referenced in films_by_reference_sorted.items():
table += "\n" table += "\n"
row_data = [] row_data = []