Compare commits
No commits in common. "570defaea9cbd42f4e9b55704e0ed77521518740" and "06ea4e0754e11c574dd46ec6c0b79303f022609d" have entirely different histories.
570defaea9
...
06ea4e0754
@ -7,12 +7,3 @@ def get_movie(imdb_id):
|
||||
movie = ia.get_movie(imdb_id)
|
||||
|
||||
return movie
|
||||
|
||||
|
||||
def get_movie_keywords(imdb_id):
|
||||
ia = IMDb()
|
||||
|
||||
movie = ia.get_movie(imdb_id, info="keywords")
|
||||
|
||||
return movie
|
||||
|
||||
|
@ -14,8 +14,8 @@ def get_films_by_reference(viewings):
|
||||
return viewings_filtered_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]))
|
||||
def build_page(reference_keywords):
|
||||
reference_keywords_sorted = OrderedDict(sorted(reference_keywords.items(), key=lambda t: t[0]))
|
||||
|
||||
films_by_reference_table = "| Referenced | Films |\n| - | - |"
|
||||
|
||||
|
@ -4,6 +4,7 @@ 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
|
||||
@ -20,13 +21,16 @@ def get_films_by_country(viewings):
|
||||
|
||||
|
||||
def build_page(films_by_country):
|
||||
table = build_table(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)
|
||||
|
||||
print("Drawing map")
|
||||
country_counter = Counter(films_by_country)
|
||||
png_data = draw_map(country_counter)
|
||||
encoded = base64.b64encode(png_data).decode("utf-8")
|
||||
image = "".format(encoded)
|
||||
page = image + "\n" + table
|
||||
page = image + "\n" + film_by_country_table
|
||||
|
||||
return page
|
||||
|
||||
@ -34,7 +38,7 @@ def build_page(films_by_country):
|
||||
def get_flags_dict():
|
||||
flags = {}
|
||||
|
||||
with open('country-flags.csv', newline='') as f:
|
||||
with open('country_flags.csv', newline='') as f:
|
||||
reader = csv.reader(f, quotechar="\"")
|
||||
next(reader, None) # skip the headers
|
||||
|
||||
@ -44,35 +48,30 @@ def get_flags_dict():
|
||||
return flags
|
||||
|
||||
|
||||
def build_table(films_by_country):
|
||||
def build_table(films_by_country, bar=None):
|
||||
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, films in films_by_country_sorted.items():
|
||||
for country in films_by_country_sorted.keys():
|
||||
table += "\n"
|
||||
|
||||
table += country
|
||||
|
||||
if country in flags.keys():
|
||||
table += " "
|
||||
table += flags[country]
|
||||
|
||||
table += "{} {}".format(str(country), flags[country] if country in flags.keys() else "")
|
||||
table += " | "
|
||||
|
||||
film_links = []
|
||||
for film in films:
|
||||
film_links.append("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']))
|
||||
|
||||
film_links = ["[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_country_sorted[country]]
|
||||
table += "<br>".join(film_links)
|
||||
|
||||
if bar is not None:
|
||||
bar.next()
|
||||
|
||||
if bar is not None:
|
||||
bar.finish()
|
||||
|
||||
return table
|
||||
|
||||
|
||||
def draw_map(films_by_country, file_name="vcinema_map.svg"):
|
||||
counter = Counter(films_by_country)
|
||||
def draw_map(counter, file_name="vcinema_map.svg"):
|
||||
countries = [k for k, v in counter.items()]
|
||||
counts = [len(v) for _, v in counter.items()]
|
||||
|
||||
|
@ -12,19 +12,22 @@ def get_films_by_year(viewings):
|
||||
return viewings_filtered_by_year
|
||||
|
||||
|
||||
def build_page(films_by_year):
|
||||
def build_page(films_by_year, progressbar=None):
|
||||
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
|
||||
|
||||
page = "| Year | Films |\n| - | - |"
|
||||
page_table = "| Year | Films |\n| - | - |"
|
||||
|
||||
for year in films_by_year_sorted.keys():
|
||||
page += "\n"
|
||||
page += str(year) + " | "
|
||||
page_table += "\n"
|
||||
page_table += str(year) + " | "
|
||||
|
||||
films = []
|
||||
for film in films_by_year_sorted[year]:
|
||||
films.append("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']))
|
||||
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)
|
||||
|
||||
page += "<br>".join(films)
|
||||
if progressbar is not None:
|
||||
progressbar.next()
|
||||
|
||||
return page
|
||||
if progressbar is not None:
|
||||
progressbar.finish()
|
||||
|
||||
return page_table
|
||||
|
@ -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):
|
||||
def filter_viewings(viewings, filter_field, progress_bar=None):
|
||||
viewings_filtered = {}
|
||||
|
||||
for viewing in viewings:
|
||||
@ -114,4 +114,9 @@ def filter_viewings(viewings, filter_field):
|
||||
else:
|
||||
viewings_filtered[viewing_field] = [viewing]
|
||||
|
||||
if progress_bar is not None:
|
||||
progress_bar.next()
|
||||
|
||||
progress_bar.finish()
|
||||
|
||||
return viewings_filtered
|
||||
|
Loading…
x
Reference in New Issue
Block a user