re-save index on Ctrl+c to hide in progress message on html output

This commit is contained in:
Nick Sweeting 2019-03-19 18:08:42 -04:00
parent 6f5abd49b4
commit 1b5201fd58
3 changed files with 13 additions and 7 deletions

View file

@ -112,6 +112,11 @@ def update_archive(archive_path, links, source=None, resume=None, append=True):
archive_link(link_dir, link)
except (KeyboardInterrupt, SystemExit, Exception) as e:
if isinstance(e, KeyboardInterrupt):
# Step 4: Re-write links index with updated titles, icons, and resources
all_links, _ = load_links(archive_path=out_dir)
write_links_index(out_dir=out_dir, links=all_links, finished=True)
print()
print('\n{lightyellow}[X] [{now}] Downloading paused on link {timestamp} ({idx}/{total}){reset}'.format(
**ANSI,
now=datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
@ -217,4 +222,4 @@ if __name__ == '__main__':
# Step 4: Re-write links index with updated titles, icons, and resources
all_links, _ = load_links(archive_path=out_dir)
write_links_index(out_dir=out_dir, links=all_links)
write_links_index(out_dir=out_dir, links=all_links, finished=True)

View file

@ -27,7 +27,7 @@ from util import (
### Homepage index for all the links
def write_links_index(out_dir, links):
def write_links_index(out_dir, links, finished=False):
"""create index.html file for a given list of links"""
check_links_structure(links)
@ -35,14 +35,14 @@ def write_links_index(out_dir, links):
if not os.path.exists(out_dir):
os.makedirs(out_dir)
print('{green}[*] [{}] Updating main index files...{reset}'.format(
print('{green}[*] [{}] Saving main index files...{reset}'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
**ANSI,
))
write_json_links_index(out_dir, links)
print(' > {}/index.json'.format(pretty_path(out_dir)))
write_html_links_index(out_dir, links)
write_html_links_index(out_dir, links, finished=finished)
print(' > {}/index.html'.format(pretty_path(out_dir)))
@ -78,7 +78,7 @@ def parse_json_links_index(out_dir):
return []
def write_html_links_index(out_dir, links):
def write_html_links_index(out_dir, links, finished=False):
"""write the html link index to a given path"""
check_links_structure(links)
@ -109,6 +109,7 @@ def write_html_links_index(out_dir, links):
'git_sha': GIT_SHA,
'short_git_sha': GIT_SHA[:8],
'rows': link_rows,
'status': 'finished' if finished else 'running',
}
with open(path, 'w', encoding='utf-8') as f:

View file

@ -100,7 +100,7 @@
}
</style>
</head>
<body>
<body data-status="$status">
<header>
<div class="header-right">
<a href="https://github.com/pirate/ArchiveBox/wiki">Documentation</a> &nbsp; | &nbsp;
@ -113,7 +113,7 @@
</a>
</div>
<div class="header-center">
Archived Sites<br/>
Archived Sites <span class="in-progress">(Currently Updating)</span><br/>
<small>Last updated $time_updated</small>
</div>
</header>