import argparse from datetime import datetime, timedelta import json from progress.bar import IncrementalBar from vcinema_utils import VCinemaUtils def get_countries(token_id, token_secret, start_date, end_date): 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) in_range_viewings = VCinemaUtils.get_viewings_in_date_range(viewings, start_date, end_date) in_range_countries = VCinemaUtils.filter_viewings(in_range_viewings, "countries") print(f"Countries in range {start_date.strftime('%d-%m-%Y')} - {end_date.strftime('%d-%m-%Y')}:") for country, films in in_range_countries.items(): print(f"{country}:{len(films)}") if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('start_date', type=lambda s: datetime.strptime(s, '%d-%m-%Y')) parser.add_argument('end_date', type=lambda s: datetime.strptime(s, '%d-%m-%Y')) args = parser.parse_args() with open('../token.json') as json_file: token = json.load(json_file) get_countries(token['token_id'], token['token_secret'], args.start_date, args.end_date)