import argparse from collections import Counter from datetime import datetime import json from progress.bar import IncrementalBar from vcinema_utils import VCinemaUtils from wiki_pages.FilmsByCountry import draw_map def get_film_map_for_date(token_id, token_secret, date, outfile): print("Getting viewings") viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret) with IncrementalBar('Retrieving movie data', max=len(viewings), suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar: VCinemaUtils.add_imdb_data_to_viewings(viewings, ["countries"], bar) viewings_before_year = VCinemaUtils.get_viewings_in_date_range(datetime.min, date) viewings_before_year_filtered_by_year = VCinemaUtils.filter_viewings(viewings_before_year, "countries") country_counter = Counter(viewings_before_year_filtered_by_year) png_data = draw_map(country_counter) print("saving map to:" + outfile) with open(outfile, "wb") as f: f.write(png_data) print("saved") if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('date', type=lambda s: datetime.strptime(s, '%d-%m-%Y')) parser.add_argument('outfile', type=str) args = parser.parse_args() with open('../token.json') as json_file: token = json.load(json_file) get_film_map_for_date(token['token_id'], token['token_secret'], args.date, args.outfile)