add markdown table
This commit is contained in:
parent
e47d22aa22
commit
d65ffbed43
35
markdown_utils/MarkdownUtils.py
Normal file
35
markdown_utils/MarkdownUtils.py
Normal 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(row)
|
||||||
|
|
||||||
|
return table
|
0
markdown_utils/__init__.py
Normal file
0
markdown_utils/__init__.py
Normal 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,13 +131,9 @@ 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'], "https://www.imdb.com/title/tt{}/".format(film['imdb_id']))
|
return MarkdownUtils.generate_markdown_link(film['title'], "https://www.imdb.com/title/tt{}/".format(film['imdb_id']))
|
||||||
|
|
||||||
|
|
||||||
def generate_wikipedia_page_link(page_title):
|
def generate_wikipedia_page_link(page_title):
|
||||||
return generate_markdown_link(page_title, "https://en.wikipedia.org/wiki/{}".format(page_title.replace(" ", "_")))
|
return MarkdownUtils.generate_markdown_link(page_title, "https://en.wikipedia.org/wiki/{}".format(page_title.replace(" ", "_")))
|
||||||
|
@ -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")
|
||||||
@ -60,7 +61,7 @@ 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"
|
table += "\n"
|
||||||
@ -75,7 +76,7 @@ def build_table(films_by_country):
|
|||||||
row_data.append(country_label)
|
row_data.append(country_label)
|
||||||
row_data.append(VCinemaUtils.get_film_list(films))
|
row_data.append(VCinemaUtils.get_film_list(films))
|
||||||
|
|
||||||
table += " | ".join(row_data)
|
table.add_row(row_data)
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ from collections import OrderedDict
|
|||||||
import string
|
import string
|
||||||
|
|
||||||
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
|
||||||
@ -23,15 +24,11 @@ def update_page(token_id, token_secret, films_by_reference_keyword):
|
|||||||
def build_page(films_by_reference_keyword):
|
def build_page(films_by_reference_keyword):
|
||||||
reference_keywords_sorted = OrderedDict(sorted(films_by_reference_keyword.items(), key=lambda t: t[0]))
|
reference_keywords_sorted = OrderedDict(sorted(films_by_reference_keyword.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
table = "| Referenced | Films |\n| - | - |"
|
table = MarkdownUtils.MarkdownTable(["Referenced", "Films"])
|
||||||
|
|
||||||
for year in reference_keywords_sorted.keys():
|
for year in reference_keywords_sorted.keys():
|
||||||
table += "\n"
|
row_data = [VCinemaUtils.generate_wikipedia_page_link(string.capwords(year[13:].replace("-", " "))),
|
||||||
|
VCinemaUtils.get_film_list(reference_keywords_sorted[year])]
|
||||||
row_data = []
|
table.add_row(row_data)
|
||||||
row_data.append(VCinemaUtils.generate_wikipedia_page_link(string.capwords(year[13:].replace("-", " "))))
|
|
||||||
row_data.append(VCinemaUtils.get_film_list(reference_keywords_sorted[year]))
|
|
||||||
|
|
||||||
table += " | ".join(row_data)
|
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
@ -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
|
||||||
@ -21,15 +22,10 @@ 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_sorted = 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_sorted.keys():
|
||||||
page += "\n"
|
row_data = [str(year), VCinemaUtils.get_film_list(films_by_year_sorted[year])]
|
||||||
|
table.add_row(row_data)
|
||||||
|
|
||||||
row_data = []
|
return table
|
||||||
row_data.append(str(year))
|
|
||||||
row_data.append(VCinemaUtils.get_film_list(films_by_year_sorted[year]))
|
|
||||||
|
|
||||||
page += " | ".join(row_data)
|
|
||||||
|
|
||||||
return page
|
|
||||||
|
@ -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,7 +61,7 @@ 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"
|
table += "\n"
|
||||||
@ -81,6 +82,6 @@ def build_page(hidden_themes):
|
|||||||
else:
|
else:
|
||||||
row_data.append("N/A")
|
row_data.append("N/A")
|
||||||
|
|
||||||
table += " | ".join(row_data)
|
table.add_row(row_data)
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
@ -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,7 +67,7 @@ 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"
|
table += "\n"
|
||||||
@ -76,6 +77,6 @@ def build_page(keyword_data, minimum_score=1.0):
|
|||||||
row_data.append(str(len(data['vcinema_films'])))
|
row_data.append(str(len(data['vcinema_films'])))
|
||||||
row_data.append(str(data['total']))
|
row_data.append(str(data['total']))
|
||||||
row_data.append(str(round(data['score'], 3)))
|
row_data.append(str(round(data['score'], 3)))
|
||||||
table += " | ".join(row_data)
|
table.add_row(row_data)
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
Loading…
x
Reference in New Issue
Block a user