better remote file downloading cli output messages

This commit is contained in:
Nick Sweeting 2019-02-21 17:52:25 -05:00
parent 44ed46b465
commit 328a59749b
2 changed files with 11 additions and 5 deletions
archivebox

View file

@ -243,10 +243,11 @@ def download_url(url, timeout=TIMEOUT):
source_path = os.path.join(SOURCES_DIR, '{}-{}.txt'.format(domain(url), ts))
print('[*] [{}] Downloading {} > {}'.format(
print('{}[*] [{}] Downloading {}{}'.format(
ANSI['green'],
datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
url,
pretty_path(source_path),
ANSI['reset'],
))
end = progress(TIMEOUT, prefix=' ')
try:
@ -254,12 +255,18 @@ def download_url(url, timeout=TIMEOUT):
end()
except Exception as e:
end()
print('[!] Failed to download {}\n'.format(url))
print('{}[!] Failed to download {}{}\n'.format(
ANSI['red'],
url,
ANSI['reset'],
))
print(' ', e)
raise SystemExit(1)
with open(source_path, 'w', encoding='utf-8') as f:
f.write(downloaded_xml)
print(' > {}'.format(pretty_path(source_path)))
return source_path