Compare commits
6 Commits
2e68577785
...
1bc467ee69
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1bc467ee69 | ||
![]() |
8506a36d9c | ||
![]() |
e4f9ea58e6 | ||
![]() |
49bdcd0847 | ||
![]() |
79ff5c76ec | ||
![]() |
1e970b4fb5 |
53
generate_map_timelapse.py
Normal file
53
generate_map_timelapse.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
from wiki_pages import FilmsByCountry
|
||||||
|
from vcinema_utils import VCinemaUtils
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from collections import OrderedDict
|
||||||
|
import imageio
|
||||||
|
from progress.bar import IncrementalBar
|
||||||
|
from pygifsicle import optimize
|
||||||
|
|
||||||
|
|
||||||
|
def generate_map_timelapse(token_id, token_secret):
|
||||||
|
print("Getting viewings")
|
||||||
|
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=False)
|
||||||
|
|
||||||
|
viewing_count = len(viewings)
|
||||||
|
with IncrementalBar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
||||||
|
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['countries'], bar)
|
||||||
|
|
||||||
|
date_viewings = VCinemaUtils.filter_viewings(viewings, "date_watched")
|
||||||
|
|
||||||
|
date_viewings = OrderedDict(sorted(date_viewings.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
|
running_country_counts = {}
|
||||||
|
print(len(date_viewings.keys()))
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
|
image = imageio.imread(FilmsByCountry.draw_map(running_country_counts, file_name="map-{}.svg".format(date)))
|
||||||
|
writer.append_data(image)
|
||||||
|
|
||||||
|
print("optimizing")
|
||||||
|
|
||||||
|
optimize("test.gif")
|
||||||
|
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='Update wiki pages.')
|
||||||
|
parser.add_argument('token_id', help='API token ID.')
|
||||||
|
parser.add_argument('token_secret', help='API token secret.')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
generate_map_timelapse(args.token_id, args.token_secret)
|
Loading…
x
Reference in New Issue
Block a user