use callback for tasks instead of adding extra function
This commit is contained in:
parent
46c4faf118
commit
91883e0133
@ -2,6 +2,7 @@ from collections import Counter
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from progress.bar import Bar
|
||||
import sys
|
||||
import functools
|
||||
|
||||
from imdb_utils import IMDbUtils
|
||||
from bookstack import Bookstack
|
||||
@ -49,18 +50,17 @@ def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True):
|
||||
return viewings
|
||||
|
||||
|
||||
def get_imdb(imdb_id, bar):
|
||||
imdb_entry = IMDbUtils.get_movie(imdb_id)
|
||||
|
||||
if bar is not None:
|
||||
def increment_progressbar(bar, _):
|
||||
bar.next()
|
||||
|
||||
return imdb_entry
|
||||
|
||||
|
||||
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}
|
||||
future_to_url = {executor.submit(IMDbUtils.get_movie, viewing['imdb_id']) for viewing in viewings}
|
||||
|
||||
if progressbar is not None:
|
||||
for this_future in future_to_url:
|
||||
this_future.add_done_callback(functools.partial(increment_progressbar, progressbar))
|
||||
|
||||
for future in as_completed(future_to_url):
|
||||
imdb_data = future.result()
|
||||
|
Loading…
x
Reference in New Issue
Block a user