From 0775d97549a309972ec020b686643deb77e80121 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sun, 18 Dec 2022 19:26:48 +0000 Subject: [PATCH] Create get_countries.py --- roundup_scripts/get_countries.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 roundup_scripts/get_countries.py diff --git a/roundup_scripts/get_countries.py b/roundup_scripts/get_countries.py new file mode 100644 index 0000000..3027afd --- /dev/null +++ b/roundup_scripts/get_countries.py @@ -0,0 +1,36 @@ +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)