improve muting wrapper for threads

This commit is contained in:
2019-09-29 14:42:09 +03:00
parent aac410f1e1
commit db8f4e1479

View File

@@ -58,13 +58,13 @@ class MovieList:
# This collects rating, genres, official name and a hyperlink
imdb = IMDb()
save_stdout = sys.stdout
sys.stdout = open('trash', 'w')
while True:
try:
query = imdb.search_movie(arg)
break
except http.client.IncompleteRead:
pass
with open(os.devnull, 'wb') as sys.stdout:
while True:
try:
query = imdb.search_movie(arg)
break
except http.client.IncompleteRead:
pass
sys.stdout = save_stdout
movie = query[0]
@@ -95,6 +95,9 @@ class MovieList:
self.src = Path(os.path.dirname(sys.argv[0])) / 'movie_list'
else:
self.src = Path(self.src)
if not self.src.exists():
sys.stderr.write(f'error: input does not exist - {self.src}\n')
return False
# Open the movie list & split the columns
with open(self.src, 'r') as fp_handle:
@@ -118,6 +121,7 @@ class MovieList:
for thread in self.threads:
thread.join()
return True
def write(self, dst=None):
""" Write the HTML list to index.html """
@@ -136,9 +140,19 @@ class MovieList:
def main():
""" Default run """
mlist = MovieList()
mlist.gen()
mlist.write()
src = dst = None
if len(sys.argv) > 3:
sys.stderr.write(f'error: max 2 variables, {len(sys.argv)-1} given!\n')
exit(1)
if len(sys.argv) > 1:
src = sys.argv[1]
if len(sys.argv) == 3:
dst = sys.argv[2]
mlist = MovieList(src=src)
if mlist.gen():
mlist.write(dst=dst)
if __name__ == "__main__":