diff --git a/__pycache__/update_films_by_country.cpython-37.pyc b/__pycache__/update_films_by_country.cpython-37.pyc new file mode 100644 index 0000000..38084ce Binary files /dev/null and b/__pycache__/update_films_by_country.cpython-37.pyc differ diff --git a/__pycache__/update_films_by_year.cpython-37.pyc b/__pycache__/update_films_by_year.cpython-37.pyc new file mode 100644 index 0000000..065b181 Binary files /dev/null and b/__pycache__/update_films_by_year.cpython-37.pyc differ diff --git a/update_films_by_country.py b/update_films_by_country.py index 654658d..eb1bc48 100644 --- a/update_films_by_country.py +++ b/update_films_by_country.py @@ -1,7 +1,5 @@ -from bookstack import Bookstack from vcinema_utils import VCinemaUtils -import argparse import base64 from collections import Counter, OrderedDict import csv @@ -12,6 +10,31 @@ import worldmap import warnings warnings.filterwarnings("ignore") +# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-country +FILMS_BY_COUNTRY_PAGE_ID = 34 + + +def get_films_by_country(viewings): + viewings_filtered_by_country = VCinemaUtils.filter_viewings(viewings, "countries") + + return viewings_filtered_by_country + + +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) + + print("Drawing map") + country_counter = Counter(films_by_country) + png_data = draw_map(country_counter) + encoded = base64.b64encode(png_data).decode("utf-8") + image_html = "".format(encoded) + + page = image_html + film_by_country_table + + return page + def get_flags_dict(): flags = {} @@ -75,7 +98,7 @@ def draw_map(counter, file_name="vcinema_map.svg"): opacity = [0.5 + (x / (float(max_count))/2.0) for x in counts] - worldmap.plot(countries, cmap=["#49E20E"], opacity=opacity, filename=file_name, verbose=False) + worldmap.plot(countries, cmap=["#FF4000"], opacity=opacity, filename=file_name, verbose=False) with Image(filename=file_name, width=1000, height=655) as i: png_data = i.make_blob("png") @@ -83,52 +106,3 @@ def draw_map(counter, file_name="vcinema_map.svg"): os.remove(file_name) return png_data - - -def update_page(map_png, table, wiki_url, token_id, token_secret): - page_id = 34 - - encoded = base64.b64encode(map_png).decode("utf-8") - - image_html = "".format(encoded) - - page_contents = image_html + table - - Bookstack.update_page(wiki_url, token_id, token_secret, page_id, html=page_contents) - - -def update_films_by_country(token_id, token_secret): - print("Retrieving VCinema viewings") - viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret) - - viewing_count = len(viewings) - - with IncrementalBar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar: - VCinemaUtils.add_imdb_data_to_viewings(viewings, ['countries'], bar) - - with IncrementalBar('Processing viewing data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar: - viewings_by_country = VCinemaUtils.filter_viewings(viewings, 'countries', bar) - - country_count = len(viewings_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(viewings_by_country, bar) - - print("Drawing map") - country_counter = Counter(viewings_by_country) - png_data = draw_map(country_counter) - - print("Updating page") - - update_page(png_data, film_by_country_table, VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret) - - print("Done!") - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Update page displaying VCinema films sorted by country.') - parser.add_argument('token_id', help='API token ID.') - parser.add_argument('token_secret', help='API token secret.') - - args = parser.parse_args() - - update_films_by_country(args.token_id, args.token_secret) diff --git a/update_films_by_year.py b/update_films_by_year.py index 6902f06..583dfaf 100644 --- a/update_films_by_year.py +++ b/update_films_by_year.py @@ -1,14 +1,17 @@ -import argparse from collections import OrderedDict -from progress.bar import IncrementalBar -from bookstack import Bookstack from vcinema_utils import VCinemaUtils # Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year FILMS_BY_YEAR_PAGE_ID = 24 +def get_films_by_year(viewings): + viewings_filtered_by_year = VCinemaUtils.filter_viewings(viewings, "year") + + return viewings_filtered_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)) @@ -26,34 +29,3 @@ def build_page(films_by_year, progressbar=None): progressbar.finish() return page_table - - -def update_films_by_year(token_id, token_secret): - print("Retrieving VCinema viewings") - viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret) - - viewing_count = len(viewings) - with IncrementalBar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar: - VCinemaUtils.add_imdb_data_to_viewings(viewings, ['year'], bar) - - with IncrementalBar('Processing viewing data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar: - viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year', bar) - - year_count = len(viewings_by_year) - with IncrementalBar('Generating table', max=year_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar: - films_by_year_page = build_page(viewings_by_year, bar) - - print("Updating page") - Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, FILMS_BY_YEAR_PAGE_ID, markdown=films_by_year_page) - - print("Done!") - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Update page displaying VCinema films sorted by release year.') - parser.add_argument('token_id', help='API token ID.') - parser.add_argument('token_secret', help='API token secret.') - - args = parser.parse_args() - - update_films_by_year(args.token_id, args.token_secret)