From 3c2e0acb9c8346d0ce0cea341cd31e9728a7b67c Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 17 Apr 2018 07:30:06 -0400 Subject: [PATCH] tweak console output formatting --- archive | 16 ++++++++++++++-- archive_methods.py | 18 ++++++++++-------- index.py | 6 +++--- links.py | 5 ----- util.py | 10 ++++------ 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/archive b/archive index 3761de4e..26b99be5 100755 --- a/archive +++ b/archive @@ -55,7 +55,7 @@ def merge_links(archive_path=HTML_FOLDER, import_path=None): num_new_links = len(all_links) - len(existing_links) if import_path: - print('[*] [{}] Adding {} new links from {} to index'.format( + print('[+] [{}] Adding {} new links from {} to index'.format( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), num_new_links, import_path, @@ -75,6 +75,18 @@ def update_archive(archive_path, links, source=None, resume=None, append=True): start_ts = datetime.now().timestamp() + if resume: + print('{green}[▶] [{}] Resuming archive update from {}...{reset}'.format( + datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + resume, + **ANSI, + )) + else: + print('{green}[▶] [{}] Running full archive update...{reset}'.format( + datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + **ANSI, + )) + # loop over links and archive them archive_links(archive_path, links, source=source, resume=resume) @@ -117,7 +129,7 @@ if __name__ == '__main__': # argv[1] is a path to a file to import source, resume = sys.argv[1].strip(), None elif argc == 3: - source, resume = sys.argv[1].strip(), sys.argv[1] + source, resume = sys.argv[1].strip(), sys.argv[2] else: print_help() raise SystemExit(1) diff --git a/archive_methods.py b/archive_methods.py index 8049a3d5..166fab1b 100644 --- a/archive_methods.py +++ b/archive_methods.py @@ -45,18 +45,19 @@ def archive_links(archive_path, links, source=None, resume=None): to_archive = Peekable(links_after_timestamp(links, resume)) idx, link = 0, to_archive.peek(0) + try: for idx, link in enumerate(to_archive): link_dir = os.path.join(archive_path, 'archive', link['timestamp']) archive_link(link_dir, link) except (KeyboardInterrupt, SystemExit, Exception) as e: - print('⏸ [{now}] {lightyellow}Downloading paused on link {timestamp} ({idx}/{total}){reset}'.format( + print('{lightyellow}[X] [{now}] Downloading paused on link {timestamp} ({idx}/{total}){reset}'.format( **ANSI, now=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), - idx=idx, + idx=idx+1, timestamp=link['timestamp'], - total=len(list(to_archive)), + total=len(links), )) print(' Continue where you left off by running:') print(' {} {} {}'.format( @@ -105,6 +106,7 @@ def archive_link(link_dir, link, overwrite=False): link = fetch_favicon(link_dir, link, overwrite=overwrite) write_link_index(link_dir, link) + print() return link @@ -115,10 +117,10 @@ def log_link_archive(link_dir, link, update_existing): **link, **ANSI, )) - if link['type']: - print(' i Type: {}'.format(link['type'])) - print(' {} ({})'.format(link_dir, 'updating' if update_existing else 'creating')) + print(' > {} ({})'.format(link_dir, 'updating' if update_existing else 'creating')) + if link['type']: + print(' i {}'.format(link['type'])) @@ -141,10 +143,10 @@ def attach_result_to_link(method): # if a valid method output is already present, dont run the fetch function if link['latest'][method] and not overwrite: - print(' √ Skipping: {}'.format(method)) + print(' √ {}'.format(method)) result = None else: - print(' - Fetching: {}'.format(method)) + print(' > {}'.format(method)) result = fetch_func(link_dir, link, **kwargs) end_ts = datetime.now().timestamp() diff --git a/index.py b/index.py index 168670d1..c5f459b7 100644 --- a/index.py +++ b/index.py @@ -33,7 +33,7 @@ def write_links_index(out_dir, links): write_json_links_index(out_dir, links) write_html_links_index(out_dir, links) - print('[√] [{}] Main archive index now up-to-date: {}/index.html'.format( + print('[√] [{}] Archive Main Index now up-to-date: {}/index.html'.format( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), out_dir, @@ -110,7 +110,7 @@ def write_json_link_index(out_dir, link): path = os.path.join(out_dir, 'index.json') - print(' √ Updating: index.json') + print(' √ index.json') with open(path, 'w', encoding='utf-8') as f: json.dump(link, f, indent=4, default=str) @@ -131,7 +131,7 @@ def write_html_link_index(out_dir, link): path = os.path.join(out_dir, 'index.html') - print(' √ Updating: index.html') + print(' √ index.html') with open(path, 'w', encoding='utf-8') as f: f.write(Template(link_html).substitute({ diff --git a/links.py b/links.py index 45143089..260dadb1 100644 --- a/links.py +++ b/links.py @@ -98,11 +98,6 @@ def links_after_timestamp(links, timestamp=None): yield from links return - print('▶️ [{}] {green}Resuming downloads at {}...{reset}'.format( - datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), - timestamp, - **ANSI, - )) for link in links: try: if float(link['timestamp']) <= float(timestamp): diff --git a/util.py b/util.py index 54caa350..2280db38 100644 --- a/util.py +++ b/util.py @@ -41,8 +41,6 @@ short_ts = lambda ts: ts.split('.')[0] def check_dependencies(): """Check that all necessary dependencies are installed, and have valid versions""" - print('[*] Checking Dependencies:') - python_vers = float('{}.{}'.format(sys.version_info.major, sys.version_info.minor)) if python_vers < 3.5: print('{}[X] Python version is not new enough: {} (>3.5 is required){}'.format(ANSI['red'], python_vers, ANSI['reset'])) @@ -50,7 +48,7 @@ def check_dependencies(): raise SystemExit(1) if FETCH_PDF or FETCH_SCREENSHOT: - if run(['which', CHROME_BINARY]).returncode: + if run(['which', CHROME_BINARY], stdout=DEVNULL).returncode: print('{}[X] Missing dependency: {}{}'.format(ANSI['red'], CHROME_BINARY, ANSI['reset'])) print(' Run ./setup.sh, then confirm it was installed with: {} --version'.format(CHROME_BINARY)) print(' See https://github.com/pirate/bookmark-archiver for help.') @@ -74,21 +72,21 @@ def check_dependencies(): raise SystemExit(1) if FETCH_WGET: - if run(['which', 'wget']).returncode or run(['wget', '--version'], stdout=DEVNULL).returncode: + if run(['which', 'wget'], stdout=DEVNULL).returncode or run(['wget', '--version'], stdout=DEVNULL).returncode: print('{red}[X] Missing dependency: wget{reset}'.format(**ANSI)) print(' Run ./setup.sh, then confirm it was installed with: {} --version'.format('wget')) print(' See https://github.com/pirate/bookmark-archiver for help.') raise SystemExit(1) if FETCH_FAVICON or SUBMIT_ARCHIVE_DOT_ORG: - if run(['which', 'curl']).returncode or run(['curl', '--version'], stdout=DEVNULL).returncode: + if run(['which', 'curl'], stdout=DEVNULL).returncode or run(['curl', '--version'], stdout=DEVNULL).returncode: print('{red}[X] Missing dependency: curl{reset}'.format(**ANSI)) print(' Run ./setup.sh, then confirm it was installed with: {} --version'.format('curl')) print(' See https://github.com/pirate/bookmark-archiver for help.') raise SystemExit(1) if FETCH_AUDIO or FETCH_VIDEO: - if run(['which', 'youtube-dl']).returncode or run(['youtube-dl', '--version'], stdout=DEVNULL).returncode: + if run(['which', 'youtube-dl'], stdout=DEVNULL).returncode or run(['youtube-dl', '--version'], stdout=DEVNULL).returncode: print('{red}[X] Missing dependency: youtube-dl{reset}'.format(**ANSI)) print(' Run ./setup.sh, then confirm it was installed with: {} --version'.format('youtube-dl')) print(' See https://github.com/pirate/bookmark-archiver for help.')