improve muting wrapper for threads
This commit is contained in:
@@ -58,7 +58,7 @@ class MovieList:
|
|||||||
# This collects rating, genres, official name and a hyperlink
|
# This collects rating, genres, official name and a hyperlink
|
||||||
imdb = IMDb()
|
imdb = IMDb()
|
||||||
save_stdout = sys.stdout
|
save_stdout = sys.stdout
|
||||||
sys.stdout = open('trash', 'w')
|
with open(os.devnull, 'wb') as sys.stdout:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
query = imdb.search_movie(arg)
|
query = imdb.search_movie(arg)
|
||||||
@@ -95,6 +95,9 @@ class MovieList:
|
|||||||
self.src = Path(os.path.dirname(sys.argv[0])) / 'movie_list'
|
self.src = Path(os.path.dirname(sys.argv[0])) / 'movie_list'
|
||||||
else:
|
else:
|
||||||
self.src = Path(self.src)
|
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
|
# Open the movie list & split the columns
|
||||||
with open(self.src, 'r') as fp_handle:
|
with open(self.src, 'r') as fp_handle:
|
||||||
@@ -118,6 +121,7 @@ class MovieList:
|
|||||||
|
|
||||||
for thread in self.threads:
|
for thread in self.threads:
|
||||||
thread.join()
|
thread.join()
|
||||||
|
return True
|
||||||
|
|
||||||
def write(self, dst=None):
|
def write(self, dst=None):
|
||||||
""" Write the HTML list to index.html """
|
""" Write the HTML list to index.html """
|
||||||
@@ -136,9 +140,19 @@ class MovieList:
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Default run """
|
""" Default run """
|
||||||
mlist = MovieList()
|
src = dst = None
|
||||||
mlist.gen()
|
if len(sys.argv) > 3:
|
||||||
mlist.write()
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user