This commit is contained in:
Sarah 2022-04-03 22:27:49 +01:00
parent 6eb3724419
commit 570defaea9
4 changed files with 30 additions and 37 deletions

View File

@ -14,8 +14,8 @@ def get_films_by_reference(viewings):
return viewings_filtered_by_reference_keyword
def build_page(reference_keywords):
reference_keywords_sorted = OrderedDict(sorted(reference_keywords.items(), key=lambda t: t[0]))
def build_page(films_by_reference_keyword):
reference_keywords_sorted = OrderedDict(sorted(films_by_reference_keyword.items(), key=lambda t: t[0]))
films_by_reference_table = "| Referenced | Films |\n| - | - |"

View File

@ -4,7 +4,6 @@ import base64
from collections import Counter, OrderedDict
import csv
import os
from progress.bar import IncrementalBar
from wand.image import Image
import worldmap
import warnings
@ -21,16 +20,13 @@ def get_films_by_country(viewings):
def build_page(films_by_country):
country_count = len(films_by_country.keys())
with IncrementalBar('Generating table', max=country_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
film_by_country_table = build_table(films_by_country, bar)
table = build_table(films_by_country)
print("Drawing map")
country_counter = Counter(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" + film_by_country_table
page = image + "\n" + table
return page
@ -48,30 +44,35 @@ def get_flags_dict():
return flags
def build_table(films_by_country, bar=None):
def build_table(films_by_country):
films_by_country_sorted = OrderedDict(sorted(films_by_country.items(), key=lambda t: t[0]))
flags = get_flags_dict()
table = "| Country | Films |\n| - | - |"
for country in films_by_country_sorted.keys():
for country, films in films_by_country_sorted.items():
table += "\n"
table += "{} {}".format(str(country), flags[country] if country in flags.keys() else "")
table += country
if country in flags.keys():
table += " "
table += flags[country]
table += " | "
film_links = ["[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_country_sorted[country]]
film_links = []
for film in films:
film_links.append("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']))
table += "<br>".join(film_links)
if bar is not None:
bar.next()
if bar is not None:
bar.finish()
return table
def draw_map(counter, file_name="vcinema_map.svg"):
def draw_map(films_by_country, file_name="vcinema_map.svg"):
counter = Counter(films_by_country)
countries = [k for k, v in counter.items()]
counts = [len(v) for _, v in counter.items()]

View File

@ -12,22 +12,19 @@ def get_films_by_year(viewings):
return viewings_filtered_by_year
def build_page(films_by_year, progressbar=None):
def build_page(films_by_year):
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
page_table = "| Year | Films |\n| - | - |"
page = "| Year | Films |\n| - | - |"
for year in films_by_year_sorted.keys():
page_table += "\n"
page_table += str(year) + " | "
page += "\n"
page += str(year) + " | "
film_links = ["[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_year_sorted[year]]
page_table += "<br>".join(film_links)
films = []
for film in films_by_year_sorted[year]:
films.append("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']))
if progressbar is not None:
progressbar.next()
page += "<br>".join(films)
if progressbar is not None:
progressbar.finish()
return page_table
return page

View File

@ -96,7 +96,7 @@ def add_imdb_data_to_viewings(viewings, field_names, progress_bar=None):
progress_bar.finish()
def filter_viewings(viewings, filter_field, progress_bar=None):
def filter_viewings(viewings, filter_field):
viewings_filtered = {}
for viewing in viewings:
@ -114,9 +114,4 @@ def filter_viewings(viewings, filter_field, progress_bar=None):
else:
viewings_filtered[viewing_field] = [viewing]
if progress_bar is not None:
progress_bar.next()
progress_bar.finish()
return viewings_filtered