From 3fca6b4a74af2336fc9ef8d18b845ca4f704cb9a Mon Sep 17 00:00:00 2001 From: Fitti Date: Thu, 1 Jul 2021 14:07:45 +0200 Subject: [PATCH 1/3] Delete file on KeyboardInterrupt and add fail warning --- clipper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clipper.py b/clipper.py index 6d642f4..fe4abc0 100644 --- a/clipper.py +++ b/clipper.py @@ -198,6 +198,7 @@ def dl_progress(count, block_size, total_size): Include the quotation marks and curly brackets!""" raise FileNotFoundError(e_msg) + failed = 0 game_ids = {} b_ids = {} start = None @@ -303,7 +304,11 @@ def dl_progress(count, block_size, total_size): upload.Upload() remove(fullpath) print() + except KeyboardInterrupt as e: + remove(fullpath) + raise e except Exception as e: + failed += 1 print(e) if not isfile(base_path + "failed.txt"): with open("failed.txt", "w"): @@ -313,3 +318,7 @@ def dl_progress(count, block_size, total_size): print(file_name + ": FAILED!") start += timedelta(days=1) + + if failed: + print(f"\n{str(failed)} clips not downloaded!" + " Check failed.txt and try downloading them manually.") From 4d471f11bad990b3d53df18aa32a5222fd456abf Mon Sep 17 00:00:00 2001 From: Fitti Date: Thu, 1 Jul 2021 14:24:10 +0200 Subject: [PATCH 2/3] Only remove existing files and exit gracefully --- clipper.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clipper.py b/clipper.py index fe4abc0..4bfe75f 100644 --- a/clipper.py +++ b/clipper.py @@ -304,9 +304,10 @@ def dl_progress(count, block_size, total_size): upload.Upload() remove(fullpath) print() - except KeyboardInterrupt as e: - remove(fullpath) - raise e + except KeyboardInterrupt: + if isfile(fullpath): + remove(fullpath) + sys.exit("Exiting...") except Exception as e: failed += 1 print(e) From 15c5fc2acea345be7191e83fa9b890c69a2510fe Mon Sep 17 00:00:00 2001 From: Fitti Date: Thu, 1 Jul 2021 14:26:35 +0200 Subject: [PATCH 3/3] Cleanup on any Exception --- clipper.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clipper.py b/clipper.py index 4bfe75f..1f8bcfa 100644 --- a/clipper.py +++ b/clipper.py @@ -309,6 +309,8 @@ def dl_progress(count, block_size, total_size): remove(fullpath) sys.exit("Exiting...") except Exception as e: + if isfile(fullpath): + remove(fullpath) failed += 1 print(e) if not isfile(base_path + "failed.txt"):