From 79ff5c76ecf3b595823ba80aba671f3a898c1906 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 22 Apr 2022 22:13:21 +0100 Subject: [PATCH] generate maps by running total --- generate_map_timelapse.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/generate_map_timelapse.py b/generate_map_timelapse.py index f487725..9213a80 100644 --- a/generate_map_timelapse.py +++ b/generate_map_timelapse.py @@ -2,6 +2,7 @@ from wiki_pages import FilmsByCountry from vcinema_utils import VCinemaUtils import argparse +from collections import OrderedDict from progress.bar import IncrementalBar @@ -15,13 +16,21 @@ def generate_map_timelapse(token_id, token_secret): date_viewings = VCinemaUtils.filter_viewings(viewings, "date_watched") + date_viewings = OrderedDict(sorted(date_viewings.items(), key=lambda t: t[0])) + + running_country_counts = {} + for date, viewings in date_viewings.items(): date_viewings_countries = VCinemaUtils.filter_viewings(viewings, "countries") - print(date_viewings_countries) + for country in date_viewings_countries: + if country in running_country_counts.keys(): + running_country_counts[country] += date_viewings_countries[country] + else: + running_country_counts[country] = date_viewings_countries[country] with open("map-{}.png".format(date), "wb") as f: - f.write(FilmsByCountry.draw_map(date_viewings_countries, file_name="map-{}.svg".format(date))) + f.write(FilmsByCountry.draw_map(running_country_counts, file_name="map-{}.svg".format(date))) if __name__ == '__main__':