pass bar into add_imdb_data_to_viewings method
This commit is contained in:
parent
98bc78b142
commit
46c4faf118
|
@ -31,7 +31,9 @@ def update_films_by_year_page(token_id, token_secret):
|
||||||
print("Retrieving VCinema viewings")
|
print("Retrieving VCinema viewings")
|
||||||
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
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')
|
viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year')
|
||||||
|
|
||||||
|
|
|
@ -52,29 +52,24 @@ def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True):
|
||||||
def get_imdb(imdb_id, bar):
|
def get_imdb(imdb_id, bar):
|
||||||
imdb_entry = IMDbUtils.get_movie(imdb_id)
|
imdb_entry = IMDbUtils.get_movie(imdb_id)
|
||||||
|
|
||||||
bar.next()
|
if bar is not None:
|
||||||
|
bar.next()
|
||||||
|
|
||||||
return imdb_entry
|
return imdb_entry
|
||||||
|
|
||||||
|
|
||||||
def add_imdb_data_to_viewings(viewings, field_names):
|
def add_imdb_data_to_viewings(viewings, field_names, progressbar=None):
|
||||||
sys.stdout.write("\rRetrieving movie data")
|
with ThreadPoolExecutor(4) as executor:
|
||||||
sys.stdout.flush()
|
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:
|
for viewing in viewings:
|
||||||
with ThreadPoolExecutor(4) as executor:
|
if viewing['imdb_id'] == imdb_data.movieID:
|
||||||
future_to_url = {executor.submit(get_imdb, viewing['imdb_id'], bar) for viewing in viewings}
|
for field_name in field_names:
|
||||||
|
if field_name in imdb_data:
|
||||||
for future in as_completed(future_to_url):
|
viewing[field_name] = imdb_data[field_name]
|
||||||
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]
|
|
||||||
|
|
||||||
|
|
||||||
def filter_viewings(viewings, filter_field):
|
def filter_viewings(viewings, filter_field):
|
||||||
|
|
Loading…
Reference in New Issue