Compare commits

..

11 Commits

Author SHA1 Message Date
Sarah f33ff0135c fix for no page url 2022-12-16 22:09:51 +00:00
Sarah b576800794 Merge branch 'master' into feature/improve-table-generation 2022-12-16 22:07:58 +00:00
Sarah 82e847cd2a fix scores page 2022-12-10 17:10:24 +00:00
Sarah 8ba89ea288 fix references page 2022-12-10 17:09:56 +00:00
Sarah 632542c139 Update FilmsByCountry.py 2022-12-10 16:55:41 +00:00
Sarah 70d4f84679 fix hidden themes page 2022-12-10 16:46:22 +00:00
Sarah 79a0c255cf fix films by year page 2022-12-10 16:41:30 +00:00
Sarah 3f420b061a fix method call 2022-12-10 16:40:33 +00:00
Sarah d64621aa73 fix table generate 2022-12-10 16:40:25 +00:00
Sarah e9a5b0ee51 Merge branch 'master' into feature/improve-table-generation 2022-12-10 15:56:03 +00:00
Sarah d65ffbed43 add markdown table 2022-12-09 20:45:50 +00:00
8 changed files with 79 additions and 60 deletions

View File

@ -0,0 +1,35 @@
def generate_markdown_link(text, url):
return "[{}]({})".format(text, url)
class MarkdownTable:
headers = []
rows = []
def __init__(self, headers):
self.headers = headers
def add_row(self, row_data):
if len(row_data) != len(self.headers):
raise Exception("Wrong number of row entries.")
else:
self.rows.append(row_data)
def __str__(self):
table = "|"
for header in self.headers:
table += " {} |".format(header)
table += "\n"
table += "|"
table += " - |" * len(self.headers)
for row in self.rows:
table += "\n"
table += " | ".join(map(str, row))
return table

View File

View File

@ -2,8 +2,9 @@ from collections import Counter
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
import csv import csv
from imdb_utils import IMDbUtils
from bookstack import Bookstack from bookstack import Bookstack
from imdb_utils import IMDbUtils
from markdown_utils import MarkdownUtils
JACKNET_WIKI_URL = "https://wiki.jacknet.io" JACKNET_WIKI_URL = "https://wiki.jacknet.io"
@ -130,16 +131,12 @@ def get_film_list(films):
return "" return ""
def generate_markdown_link(text, url):
return "[{}]({})".format(text, url)
def generate_imdb_film_link(film): def generate_imdb_film_link(film):
return generate_markdown_link(film['title'], generate_imdb_url(film['imdb_id'])) return MarkdownUtils.generate_markdown_link(film['title'], generate_imdb_url(film['imdb_id']))
def generate_wikipedia_page_link(page_title): def generate_wikipedia_page_link(page_title):
return generate_markdown_link(page_title, generate_wikipedia_url(page_title)) return MarkdownUtils.generate_markdown_link(page_title, generate_wikipedia_url(page_title))
def generate_imdb_url(imdb_id): def generate_imdb_url(imdb_id):

View File

@ -7,6 +7,7 @@ import worldmap
import warnings import warnings
from bookstack import Bookstack from bookstack import Bookstack
from markdown_utils import MarkdownUtils
from vcinema_utils import VCinemaUtils from vcinema_utils import VCinemaUtils
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
@ -37,7 +38,7 @@ def build_page(films_by_country):
png_data = draw_map(country_counter) png_data = draw_map(country_counter)
encoded = base64.b64encode(png_data).decode("utf-8") encoded = base64.b64encode(png_data).decode("utf-8")
image = "![](data:image/png;base64,{})".format(encoded) image = "![](data:image/png;base64,{})".format(encoded)
page = image + "\n" + table page = image + "\n" + str(table)
return page return page
@ -60,22 +61,17 @@ def build_table(films_by_country):
flags = get_flags_dict() flags = get_flags_dict()
table = "| Country | Films |\n| - | - |" table = MarkdownUtils.MarkdownTable(["Country", "Films"])
for country, films in films_by_country_sorted.items(): for country, films in films_by_country_sorted.items():
table += "\n"
row_data = []
country_label = country
if country in flags.keys(): if country in flags.keys():
country_label += " " country += " " + flags[country]
country_label += flags[country]
row_data.append(country_label) films = VCinemaUtils.get_film_list(films)
row_data.append(VCinemaUtils.get_film_list(films))
table += " | ".join(row_data) row_data = [country, films]
table.add_row(row_data)
return table return table

View File

@ -2,6 +2,7 @@ from collections import OrderedDict
import wikipedia import wikipedia
from bookstack import Bookstack from bookstack import Bookstack
from markdown_utils import MarkdownUtils
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
@ -79,22 +80,15 @@ def update_page(token_id, token_secret, films_by_reference_keyword):
def build_page(films_by_reference): def build_page(films_by_reference):
films_by_reference = OrderedDict(sorted(films_by_reference.items(), key=lambda t: t[0])) films_by_reference = OrderedDict(sorted(films_by_reference.items(), key=lambda t: t[0]))
table = "| Referenced | Films |\n| - | - |" table = MarkdownUtils.MarkdownTable(["Referenced", "Films"])
for reference, referenced in films_by_reference.items(): for reference, referenced in films_by_reference.items():
table += "\n" if referenced["url"] is not None:
reference = MarkdownUtils.generate_markdown_link(reference, referenced["url"])
films = VCinemaUtils.get_film_list(referenced["films"])
row_data = [] row_data = [reference, films]
reference_url = referenced["url"] table.add_row(row_data)
referenced_films = referenced["films"]
if reference_url is None: return str(table)
row_data.append(reference)
else:
row_data.append(VCinemaUtils.generate_markdown_link(reference, reference_url))
row_data.append(VCinemaUtils.get_film_list(referenced_films))
table += " | ".join(row_data)
return table

View File

@ -1,6 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
from bookstack import Bookstack from bookstack import Bookstack
from markdown_utils import MarkdownUtils
from vcinema_utils import VCinemaUtils from vcinema_utils import VCinemaUtils
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year # Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
@ -19,17 +20,14 @@ def update_page(token_id, token_secret, films_by_year):
def build_page(films_by_year): def build_page(films_by_year):
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True)) films_by_year = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
page = "| Year | Films |\n| - | - |" table = MarkdownUtils.MarkdownTable(["Year", "Films"])
for year in films_by_year_sorted.keys(): for year in films_by_year.keys():
page += "\n" films = VCinemaUtils.get_film_list(films_by_year[year])
row_data = [] row_data = [year, films]
row_data.append(str(year)) table.add_row(row_data)
row_data.append(VCinemaUtils.get_film_list(films_by_year_sorted[year]))
page += " | ".join(row_data) return str(table)
return page

View File

@ -1,6 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
from bookstack import Bookstack from bookstack import Bookstack
from markdown_utils import MarkdownUtils
from vcinema_utils import VCinemaUtils from vcinema_utils import VCinemaUtils
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-reference # Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-reference
@ -60,14 +61,11 @@ def update_page(token_id, token_secret, hidden_themes):
def build_page(hidden_themes): def build_page(hidden_themes):
hidden_themes = OrderedDict(sorted(hidden_themes.items(), key=lambda t: t[0])) hidden_themes = OrderedDict(sorted(hidden_themes.items(), key=lambda t: t[0]))
table = "| Date | Films | Hidden Themes |\n| - | - | - |" table = MarkdownUtils.MarkdownTable(["Date", "Films", "Hidden Themes"])
for date, data in hidden_themes.items(): for date, data in hidden_themes.items():
table += "\n" films = VCinemaUtils.get_film_list(data['viewings'])
row_data = []
row_data.append(str(date))
row_data.append(VCinemaUtils.get_film_list(data['viewings']))
if 'hidden_themes' in data and data['hidden_themes'] != {}: if 'hidden_themes' in data and data['hidden_themes'] != {}:
hidden_theme_labels = [] hidden_theme_labels = []
@ -77,10 +75,11 @@ def build_page(hidden_themes):
else: else:
hidden_theme_labels.append("<i>{} ({}%)</i>".format(hidden_theme, round(data['hidden_themes'][hidden_theme] * 100))) hidden_theme_labels.append("<i>{} ({}%)</i>".format(hidden_theme, round(data['hidden_themes'][hidden_theme] * 100)))
row_data.append("<br>".join(hidden_theme_labels)) hidden_themes = "<br>".join(hidden_theme_labels)
else: else:
row_data.append("N/A") hidden_themes = "N/A"
table += " | ".join(row_data) row_data = [date, films, hidden_themes]
table.add_row(row_data)
return table return str(table)

View File

@ -5,6 +5,7 @@ from concurrent.futures import ThreadPoolExecutor
from bookstack import Bookstack from bookstack import Bookstack
from imdb_utils import IMDbUtils from imdb_utils import IMDbUtils
from markdown_utils import MarkdownUtils
from vcinema_utils import VCinemaUtils from vcinema_utils import VCinemaUtils
# Page ID of https://wiki.jacknet.io/books/vcinema/page/keyword-scores # Page ID of https://wiki.jacknet.io/books/vcinema/page/keyword-scores
@ -66,16 +67,15 @@ def build_page(keyword_data, minimum_score=1.0):
keyword_data = {k: v for k, v in keyword_data.items() if 'score' in v and v['score'] >= minimum_score} keyword_data = {k: v for k, v in keyword_data.items() if 'score' in v and v['score'] >= minimum_score}
keyword_data = OrderedDict(sorted(keyword_data.items(), key=lambda t: t[1]['score'], reverse=True)) keyword_data = OrderedDict(sorted(keyword_data.items(), key=lambda t: t[1]['score'], reverse=True))
table = "| Keyword | Number of VCinema Films | Total IMDb entries | Score |\n| - | - | - | - |" table = MarkdownUtils.MarkdownTable(["Keyword", "Number of VCinema Films", "Total IMDb entries", "Score"])
for keyword, data in keyword_data.items(): for keyword, data in keyword_data.items():
table += "\n" number_of_vcinema_films = len(data['vcinema_films'])
number_of_imdb_films = data['total']
keyword_score = round(data['score'], 3)
row_data = [] row_data = [keyword, number_of_vcinema_films, number_of_imdb_films, keyword_score]
row_data.append(str(keyword))
row_data.append(str(len(data['vcinema_films']))) table.add_row(row_data)
row_data.append(str(data['total']))
row_data.append(str(round(data['score'], 3)))
table += " | ".join(row_data)
return table return table