vcinema/roundup_scripts/get_film_map_for_date.py

45 lines
1.4 KiB
Python
Raw Permalink Normal View History

2022-12-18 17:05:34 +00:00
import argparse
2022-12-18 18:51:21 +00:00
from collections import Counter
2022-12-18 17:05:34 +00:00
from datetime import datetime
import json
from progress.bar import IncrementalBar
from vcinema_utils import VCinemaUtils
from wiki_pages.FilmsByCountry import draw_map
2022-12-18 18:51:21 +00:00
def get_film_map_for_date(token_id, token_secret, date, outfile):
2022-12-18 17:05:34 +00:00
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)
2022-12-18 18:51:21 +00:00
viewings_before_year = VCinemaUtils.get_viewings_in_date_range(datetime.min, date)
2022-12-18 17:05:34 +00:00
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)
2022-12-18 18:51:21 +00:00
print("saving map to:" + outfile)
with open(outfile, "wb") as f:
2022-12-18 17:05:34 +00:00
f.write(png_data)
2022-12-18 18:51:21 +00:00
print("saved")
2022-12-18 17:05:34 +00:00
if __name__ == '__main__':
2022-12-18 18:51:21 +00:00
parser = argparse.ArgumentParser()
2022-12-18 17:05:34 +00:00
2022-12-18 18:51:21 +00:00
parser.add_argument('date', type=lambda s: datetime.strptime(s, '%d-%m-%Y'))
parser.add_argument('outfile', type=str)
2022-12-18 17:05:34 +00:00
args = parser.parse_args()
with open('../token.json') as json_file:
token = json.load(json_file)
2022-12-18 18:51:21 +00:00
get_film_map_for_date(token['token_id'], token['token_secret'], args.date, args.outfile)