1
0
mirror of https://github.com/pirate/ArchiveBox.git synced 2025-08-24 07:03:03 +02:00

tweak console output format

This commit is contained in:
Nick Sweeting
2018-04-17 09:11:27 -04:00
parent 262fa0e1bb
commit 64e6eb5f7b
3 changed files with 41 additions and 35 deletions

22
archive
View File

@@ -54,18 +54,20 @@ def merge_links(archive_path=HTML_FOLDER, import_path=None):
all_links = validate_links(existing_links + all_links) all_links = validate_links(existing_links + all_links)
num_new_links = len(all_links) - len(existing_links) num_new_links = len(all_links) - len(existing_links)
if import_path: if num_new_links:
print('[+] [{}] Adding {} new links from {} to index'.format( print('[{green}+{reset}] [{}] Adding {} new links from {} to {}/index.json'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
num_new_links, num_new_links,
import_path, import_path,
archive_path,
**ANSI,
)) ))
else: else:
print('[*] [{}] Running on existing index with {}{}{} links.'.format( print('[*] [{}] No new links added to {}/index.json{}'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
ANSI['green'], archive_path,
len(all_links), ' from {}'.format(import_path) if import_path else '',
ANSI['reset'], **ANSI,
)) ))
return all_links return all_links
@@ -76,14 +78,15 @@ def update_archive(archive_path, links, source=None, resume=None, append=True):
start_ts = datetime.now().timestamp() start_ts = datetime.now().timestamp()
if resume: if resume:
print('{green}[▶] [{}] Resuming archive update from {}...{reset}'.format( print('{green}[▶] [{}] Resuming archive downloading from {}...{reset}'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
resume, resume,
**ANSI, **ANSI,
)) ))
else: else:
print('{green}[▶] [{}] Running full archive update...{reset}'.format( print('{green}[▶] [{}] Updating files for {} links in archive...{reset}'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
len(links),
**ANSI, **ANSI,
)) ))
@@ -98,9 +101,10 @@ def update_archive(archive_path, links, source=None, resume=None, append=True):
else: else:
duration = '{0:.2f} sec'.format(seconds, 2) duration = '{0:.2f} sec'.format(seconds, 2)
print('{}[√] [{}] Archive update complete ({}){}'.format( print('{}[√] [{}] Update of {} links complete ({}){}'.format(
ANSI['green'], ANSI['green'],
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
len(links),
duration, duration,
ANSI['reset'], ANSI['reset'],
)) ))

View File

@@ -111,14 +111,15 @@ def archive_link(link_dir, link, overwrite=False):
return link return link
def log_link_archive(link_dir, link, update_existing): def log_link_archive(link_dir, link, update_existing):
print('[{symbol_color}{symbol}{reset}] [{timestamp}] "{title}": {blue}{base_url}{reset}'.format( print('[{symbol_color}{symbol}{reset}] [{now}] "{title}"\n {blue}{url}{reset}'.format(
symbol='*' if update_existing else '+', symbol='*' if update_existing else '+',
symbol_color=ANSI['black' if update_existing else 'green'], symbol_color=ANSI['black' if update_existing else 'green'],
now=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
**link, **link,
**ANSI, **ANSI,
)) ))
print(' > {} ({})'.format(link_dir, 'updating' if update_existing else 'creating')) print(' > {}{}'.format(link_dir, '' if update_existing else ' (new)'))
if link['type']: if link['type']:
print(' i {}'.format(link['type'])) print(' i {}'.format(link['type']))
@@ -196,11 +197,12 @@ def fetch_wget(link_dir, link, requisites=FETCH_WGET_REQUISITES, timeout=TIMEOUT
try: try:
result = run(CMD, stdout=PIPE, stderr=PIPE, cwd=link_dir, timeout=timeout + 1) # index.html result = run(CMD, stdout=PIPE, stderr=PIPE, cwd=link_dir, timeout=timeout + 1) # index.html
end() end()
output = html_appended_url(link) output = wget_output_path(link, look_in=domain_dir)
if result.returncode > 0: if result.returncode > 0 and result.returncode != 8:
print(' got wget response code {}:'.format(result.returncode)) print(' got wget response code {}:'.format(result.returncode))
print('\n'.join(' ' + line for line in (result.stderr or result.stdout).decode().rsplit('\n', 10)[-10:] if line.strip())) print('\n'.join(' ' + line for line in (result.stderr or result.stdout).decode().rsplit('\n', 10)[-10:] if line.strip()))
# raise Exception('Failed to wget download') if result.returncode == 4:
raise Exception('Failed to wget download')
except Exception as e: except Exception as e:
end() end()
print(' Run to see full output:', 'cd {}; {}'.format(link_dir, ' '.join(CMD))) print(' Run to see full output:', 'cd {}; {}'.format(link_dir, ' '.join(CMD)))

View File

@@ -33,11 +33,11 @@ def write_links_index(out_dir, links):
write_json_links_index(out_dir, links) write_json_links_index(out_dir, links)
write_html_links_index(out_dir, links) write_html_links_index(out_dir, links)
print('[√] [{}] Archive Main Index now up-to-date: {}/index.html'.format( print('{green}[√] [{}] Updated main index files:{reset}'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
out_dir, **ANSI))
print(' > {}/index.json'.format(out_dir))
)) print(' > {}/index.html'.format(out_dir))
def write_json_links_index(out_dir, links): def write_json_links_index(out_dir, links):
"""write the json link index to a given path""" """write the json link index to a given path"""