diff --git a/generate_map_timelapse.py b/generate_map_timelapse.py index 9213a80..464c3b7 100644 --- a/generate_map_timelapse.py +++ b/generate_map_timelapse.py @@ -5,6 +5,7 @@ import argparse from collections import OrderedDict from progress.bar import IncrementalBar +import imageio def generate_map_timelapse(token_id, token_secret): print("Getting viewings") @@ -19,18 +20,25 @@ def generate_map_timelapse(token_id, token_secret): date_viewings = OrderedDict(sorted(date_viewings.items(), key=lambda t: t[0])) running_country_counts = {} + print(len(date_viewings.keys())) - for date, viewings in date_viewings.items(): - date_viewings_countries = VCinemaUtils.filter_viewings(viewings, "countries") + with imageio.get_writer('test.gif', mode='I', duration=0.1) as writer: + for date, viewings in date_viewings.items(): + date_viewings_countries = VCinemaUtils.filter_viewings(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] + 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(running_country_counts, file_name="map-{}.svg".format(date))) + with open("map-{}.png".format(date), "wb") as f: + f.write(FilmsByCountry.draw_map(running_country_counts, file_name="map-{}.svg".format(date))) + + image = imageio.imread("map-{}.png".format(date)) + writer.append_data(image) + + print("done") if __name__ == '__main__':