From 08c22b1277e10c62fa59ef29180da98b2c3a686a Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 23 Dec 2022 16:36:49 +0000 Subject: [PATCH] fix for reference and fix imports --- vcinema_utils/VCinemaFilm.py | 4 ++-- wiki_pages/FilmsByReference.py | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/vcinema_utils/VCinemaFilm.py b/vcinema_utils/VCinemaFilm.py index 0356530..54555d2 100644 --- a/vcinema_utils/VCinemaFilm.py +++ b/vcinema_utils/VCinemaFilm.py @@ -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 diff --git a/wiki_pages/FilmsByReference.py b/wiki_pages/FilmsByReference.py index 0695c52..dab9f22 100644 --- a/wiki_pages/FilmsByReference.py +++ b/wiki_pages/FilmsByReference.py @@ -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