pass bar into add_imdb_data_to_viewings method

This commit is contained in:
Sarah 2022-02-27 14:41:52 +00:00
parent 98bc78b142
commit 46c4faf118
2 changed files with 15 additions and 18 deletions

View File

@ -31,7 +31,9 @@ def update_films_by_year_page(token_id, token_secret):
print("Retrieving VCinema viewings")
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['year'])
viewing_count = len(viewings)
with Bar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining') as bar:
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['year'], bar)
viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year')

View File

@ -52,29 +52,24 @@ def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True):
def get_imdb(imdb_id, bar):
imdb_entry = IMDbUtils.get_movie(imdb_id)
bar.next()
if bar is not None:
bar.next()
return imdb_entry
def add_imdb_data_to_viewings(viewings, field_names):
sys.stdout.write("\rRetrieving movie data")
sys.stdout.flush()
def add_imdb_data_to_viewings(viewings, field_names, progressbar=None):
with ThreadPoolExecutor(4) as executor:
future_to_url = {executor.submit(get_imdb, viewing['imdb_id'], progressbar) for viewing in viewings}
viewing_count = len(viewings)
for future in as_completed(future_to_url):
imdb_data = future.result()
with Bar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining') as bar:
with ThreadPoolExecutor(4) as executor:
future_to_url = {executor.submit(get_imdb, viewing['imdb_id'], bar) for viewing in viewings}
for future in as_completed(future_to_url):
imdb_data = future.result()
for viewing in viewings:
if viewing['imdb_id'] == imdb_data.movieID:
for field_name in field_names:
if field_name in imdb_data:
viewing[field_name] = imdb_data[field_name]
for viewing in viewings:
if viewing['imdb_id'] == imdb_data.movieID:
for field_name in field_names:
if field_name in imdb_data:
viewing[field_name] = imdb_data[field_name]
def filter_viewings(viewings, filter_field):