Last active
March 9, 2018 11:57
-
-
Save kolotaev/6c03faecc062e8782ae082ad8c8e8599 to your computer and use it in GitHub Desktop.
wget that interrupts its execution and resumes back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# usage: ./wget.py link-to-download [interrupt-timeout] | |
import subprocess | |
import sys | |
download_timeout = 60 * 3 # 3 minutes - default | |
if len(sys.argv) < 2: | |
print('Provide link to download') | |
exit(1) | |
if len(sys.argv) == 3: | |
download_timeout = 60 * int(sys.argv[2]) | |
cmd = ['wget', '-c', sys.argv[1]] | |
while True: | |
try: | |
subprocess.run(cmd, timeout=download_timeout, check=True) | |
except subprocess.TimeoutExpired: | |
pass | |
except Exception as e: | |
print('Error %s' % e) | |
exit(1) | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment