Compare commits
No commits in common. "feature/improve-table-generation" and "master" have entirely different histories.
feature/im
...
master
|
@ -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
|
|
|
@ -2,9 +2,8 @@ from collections import Counter
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
from bookstack import Bookstack
|
|
||||||
from imdb_utils import IMDbUtils
|
from imdb_utils import IMDbUtils
|
||||||
from markdown_utils import MarkdownUtils
|
from bookstack import Bookstack
|
||||||
|
|
||||||
|
|
||||||
JACKNET_WIKI_URL = "https://wiki.jacknet.io"
|
JACKNET_WIKI_URL = "https://wiki.jacknet.io"
|
||||||
|
@ -131,12 +130,16 @@ 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 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):
|
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):
|
def generate_imdb_url(imdb_id):
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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")
|
||||||
|
@ -38,7 +37,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" + str(table)
|
page = image + "\n" + table
|
||||||
|
|
||||||
return page
|
return page
|
||||||
|
|
||||||
|
@ -61,17 +60,22 @@ def build_table(films_by_country):
|
||||||
|
|
||||||
flags = get_flags_dict()
|
flags = get_flags_dict()
|
||||||
|
|
||||||
table = MarkdownUtils.MarkdownTable(["Country", "Films"])
|
table = "| Country | Films |\n| - | - |"
|
||||||
|
|
||||||
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 += " " + 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 += " | ".join(row_data)
|
||||||
|
|
||||||
table.add_row(row_data)
|
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ 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
|
||||||
|
@ -80,15 +79,22 @@ 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 = MarkdownUtils.MarkdownTable(["Referenced", "Films"])
|
table = "| Referenced | Films |\n| - | - |"
|
||||||
|
|
||||||
for reference, referenced in films_by_reference.items():
|
for reference, referenced in films_by_reference.items():
|
||||||
if referenced["url"] is not None:
|
table += "\n"
|
||||||
reference = MarkdownUtils.generate_markdown_link(reference, referenced["url"])
|
|
||||||
films = VCinemaUtils.get_film_list(referenced["films"])
|
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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
|
||||||
|
@ -20,14 +19,17 @@ 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 = 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():
|
for year in films_by_year_sorted.keys():
|
||||||
films = VCinemaUtils.get_film_list(films_by_year[year])
|
page += "\n"
|
||||||
|
|
||||||
row_data = [year, films]
|
row_data = []
|
||||||
table.add_row(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
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
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
|
||||||
|
@ -61,11 +60,14 @@ 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 = MarkdownUtils.MarkdownTable(["Date", "Films", "Hidden Themes"])
|
table = "| Date | Films | Hidden Themes |\n| - | - | - |"
|
||||||
|
|
||||||
for date, data in hidden_themes.items():
|
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'] != {}:
|
if 'hidden_themes' in data and data['hidden_themes'] != {}:
|
||||||
hidden_theme_labels = []
|
hidden_theme_labels = []
|
||||||
|
|
||||||
|
@ -75,11 +77,10 @@ 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)))
|
||||||
|
|
||||||
hidden_themes = "<br>".join(hidden_theme_labels)
|
row_data.append("<br>".join(hidden_theme_labels))
|
||||||
else:
|
else:
|
||||||
hidden_themes = "N/A"
|
row_data.append("N/A")
|
||||||
|
|
||||||
row_data = [date, films, hidden_themes]
|
table += " | ".join(row_data)
|
||||||
table.add_row(row_data)
|
|
||||||
|
|
||||||
return str(table)
|
return table
|
||||||
|
|
|
@ -5,7 +5,6 @@ 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
|
||||||
|
@ -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 = {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 = 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():
|
for keyword, data in keyword_data.items():
|
||||||
number_of_vcinema_films = len(data['vcinema_films'])
|
table += "\n"
|
||||||
number_of_imdb_films = data['total']
|
|
||||||
keyword_score = round(data['score'], 3)
|
|
||||||
|
|
||||||
row_data = [keyword, number_of_vcinema_films, number_of_imdb_films, keyword_score]
|
row_data = []
|
||||||
|
row_data.append(str(keyword))
|
||||||
table.add_row(row_data)
|
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
|
return table
|
||||||
|
|
Loading…
Reference in New Issue