fix for reference and fix imports

This commit is contained in:
Sarah 2022-12-23 16:36:49 +00:00
parent 15f04eabd4
commit 08c22b1277
2 changed files with 13 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import vcinema_utils
from vcinema_utils.VCinemaUtils import *
from vcinema_utils.Viewing import Viewing
@ -28,7 +28,7 @@ class VCinemaFilm:
return "https://www.imdb.com/title/tt{}/".format(self._imdb_id)
def get_imdb_link(self):
return vcinema_utils.VCinemaUtils.generate_markdown_link(self._title, self.get_imdb_url())
return generate_markdown_link(self._title, self.get_imdb_url())
def get_title(self):
return self._title

View File

@ -2,23 +2,23 @@ from collections import OrderedDict
import wikipedia
from bookstack import Bookstack
from vcinema_utils import VCinemaUtils
from vcinema_utils import VCinemaUtils, VCinemaFilm
# Page ID of https://wiki.jacknet.io/books/vcinema/page/references
PAGE_ID = 62
def get_films_by_reference(viewings):
def get_films_by_reference(films: [VCinemaFilm]):
films_by_reference = {}
for viewing in viewings:
if "keywords" in viewing.keys():
for keyword in viewing["keywords"]:
for film in films:
if (film_keywords := film.get_imdb_data("keywords")) is not None:
for keyword in film_keywords:
if keyword.startswith("reference-to-"):
for reference in films_by_reference:
if keyword in films_by_reference[reference]["keywords"]:
films_by_reference[reference]["films"].append(viewing)
films_by_reference[reference]["films"].append(film)
break
else:
keyword = keyword[13:]
@ -31,13 +31,13 @@ def get_films_by_reference(viewings):
referenced = keyword.replace("-", " ")
searches = wikipedia.search(referenced, suggestion=False)
try:
searches = wikipedia.search(referenced, suggestion=False)
referenced_page = wikipedia.page(title=referenced, auto_suggest=False)
page_title = referenced_page.title
page_url = referenced_page.url
except wikipedia.DisambiguationError as e:
page_title = e.title
page_title = page_title[0].upper() + page_title[1:]
@ -60,13 +60,13 @@ def get_films_by_reference(viewings):
if page_title in films_by_reference.keys():
films_by_reference[page_title]["keywords"].append(keyword)
if viewing not in films_by_reference[page_title]["films"]:
films_by_reference[page_title]["films"].append(viewing)
if film not in films_by_reference[page_title]["films"]:
films_by_reference[page_title]["films"].append(film)
else:
films_by_reference[page_title] = {"url": page_url,
"keywords": [keyword],
"films": [viewing]}
"films": [film]}
return films_by_reference