refactor
This commit is contained in:
parent
6eb3724419
commit
570defaea9
@ -14,8 +14,8 @@ def get_films_by_reference(viewings):
|
|||||||
return viewings_filtered_by_reference_keyword
|
return viewings_filtered_by_reference_keyword
|
||||||
|
|
||||||
|
|
||||||
def build_page(reference_keywords):
|
def build_page(films_by_reference_keyword):
|
||||||
reference_keywords_sorted = OrderedDict(sorted(reference_keywords.items(), key=lambda t: t[0]))
|
reference_keywords_sorted = OrderedDict(sorted(films_by_reference_keyword.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
films_by_reference_table = "| Referenced | Films |\n| - | - |"
|
films_by_reference_table = "| Referenced | Films |\n| - | - |"
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import base64
|
|||||||
from collections import Counter, OrderedDict
|
from collections import Counter, OrderedDict
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
from progress.bar import IncrementalBar
|
|
||||||
from wand.image import Image
|
from wand.image import Image
|
||||||
import worldmap
|
import worldmap
|
||||||
import warnings
|
import warnings
|
||||||
@ -21,16 +20,13 @@ def get_films_by_country(viewings):
|
|||||||
|
|
||||||
|
|
||||||
def build_page(films_by_country):
|
def build_page(films_by_country):
|
||||||
country_count = len(films_by_country.keys())
|
table = build_table(films_by_country)
|
||||||
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)
|
|
||||||
|
|
||||||
print("Drawing map")
|
|
||||||
country_counter = Counter(films_by_country)
|
country_counter = Counter(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 = "".format(encoded)
|
image = "".format(encoded)
|
||||||
page = image + "\n" + film_by_country_table
|
page = image + "\n" + table
|
||||||
|
|
||||||
return page
|
return page
|
||||||
|
|
||||||
@ -48,30 +44,35 @@ def get_flags_dict():
|
|||||||
return flags
|
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]))
|
films_by_country_sorted = OrderedDict(sorted(films_by_country.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
flags = get_flags_dict()
|
flags = get_flags_dict()
|
||||||
|
|
||||||
table = "| Country | Films |\n| - | - |"
|
table = "| Country | Films |\n| - | - |"
|
||||||
|
|
||||||
for country in films_by_country_sorted.keys():
|
for country, films in films_by_country_sorted.items():
|
||||||
table += "\n"
|
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 += " | "
|
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)
|
table += "<br>".join(film_links)
|
||||||
|
|
||||||
if bar is not None:
|
|
||||||
bar.next()
|
|
||||||
|
|
||||||
if bar is not None:
|
|
||||||
bar.finish()
|
|
||||||
|
|
||||||
return table
|
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()]
|
countries = [k for k, v in counter.items()]
|
||||||
counts = [len(v) for _, v in counter.items()]
|
counts = [len(v) for _, v in counter.items()]
|
||||||
|
|
||||||
|
@ -12,22 +12,19 @@ def get_films_by_year(viewings):
|
|||||||
return viewings_filtered_by_year
|
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))
|
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():
|
for year in films_by_year_sorted.keys():
|
||||||
page_table += "\n"
|
page += "\n"
|
||||||
page_table += str(year) + " | "
|
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]]
|
films = []
|
||||||
page_table += "<br>".join(film_links)
|
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:
|
page += "<br>".join(films)
|
||||||
progressbar.next()
|
|
||||||
|
|
||||||
if progressbar is not None:
|
return page
|
||||||
progressbar.finish()
|
|
||||||
|
|
||||||
return page_table
|
|
||||||
|
@ -96,7 +96,7 @@ def add_imdb_data_to_viewings(viewings, field_names, progress_bar=None):
|
|||||||
progress_bar.finish()
|
progress_bar.finish()
|
||||||
|
|
||||||
|
|
||||||
def filter_viewings(viewings, filter_field, progress_bar=None):
|
def filter_viewings(viewings, filter_field):
|
||||||
viewings_filtered = {}
|
viewings_filtered = {}
|
||||||
|
|
||||||
for viewing in viewings:
|
for viewing in viewings:
|
||||||
@ -114,9 +114,4 @@ def filter_viewings(viewings, filter_field, progress_bar=None):
|
|||||||
else:
|
else:
|
||||||
viewings_filtered[viewing_field] = [viewing]
|
viewings_filtered[viewing_field] = [viewing]
|
||||||
|
|
||||||
if progress_bar is not None:
|
|
||||||
progress_bar.next()
|
|
||||||
|
|
||||||
progress_bar.finish()
|
|
||||||
|
|
||||||
return viewings_filtered
|
return viewings_filtered
|
||||||
|
Loading…
x
Reference in New Issue
Block a user