Compare commits

..

No commits in common. "feature/improve-table-generation" and "master" have entirely different histories.

8 changed files with 60 additions and 79 deletions

View File

@ -1,35 +0,0 @@
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

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

View File

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

View File

@ -2,7 +2,6 @@ from collections import OrderedDict
import wikipedia
from bookstack import Bookstack
from markdown_utils import MarkdownUtils
from vcinema_utils import VCinemaUtils
# Page ID of https://wiki.jacknet.io/books/vcinema/page/references
@ -80,15 +79,22 @@ def update_page(token_id, token_secret, films_by_reference_keyword):
def build_page(films_by_reference):
films_by_reference = OrderedDict(sorted(films_by_reference.items(), key=lambda t: t[0]))
table = MarkdownUtils.MarkdownTable(["Referenced", "Films"])
table = "| Referenced | Films |\n| - | - |"
for reference, referenced in films_by_reference.items():
if referenced["url"] is not None:
reference = MarkdownUtils.generate_markdown_link(reference, referenced["url"])
films = VCinemaUtils.get_film_list(referenced["films"])
table += "\n"
row_data = [reference, films]
row_data = []
table.add_row(row_data)
reference_url = referenced["url"]
referenced_films = referenced["films"]
return str(table)
if reference_url is None:
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,7 +1,6 @@
from collections import OrderedDict
from bookstack import Bookstack
from markdown_utils import MarkdownUtils
from vcinema_utils import VCinemaUtils
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
@ -20,14 +19,17 @@ def update_page(token_id, token_secret, films_by_year):
def build_page(films_by_year):
films_by_year = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
table = MarkdownUtils.MarkdownTable(["Year", "Films"])
page = "| Year | Films |\n| - | - |"
for year in films_by_year.keys():
films = VCinemaUtils.get_film_list(films_by_year[year])
for year in films_by_year_sorted.keys():
page += "\n"
row_data = [year, films]
table.add_row(row_data)
row_data = []
row_data.append(str(year))
row_data.append(VCinemaUtils.get_film_list(films_by_year_sorted[year]))
return str(table)
page += " | ".join(row_data)
return page

View File

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

View File

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