mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-10 06:34:16 +00:00
Merge pull request #43 from m-rossi/custom_archive_dir
Add custom archive directory as configuration option.
This commit is contained in:
commit
a0c39bc725
4 changed files with 11 additions and 7 deletions
|
@ -13,6 +13,7 @@ from index import dump_index
|
|||
from fetch import dump_website
|
||||
from config import (
|
||||
ARCHIVE_PERMISSIONS,
|
||||
ARCHIVE_DIR,
|
||||
ANSI,
|
||||
check_dependencies,
|
||||
)
|
||||
|
@ -46,11 +47,11 @@ def create_archive(export_file, service=None, resume=None):
|
|||
print('[X] No links found in {}, is it a {} export file?'.format(export_file, service))
|
||||
raise SystemExit(1)
|
||||
|
||||
if not os.path.exists(service):
|
||||
os.makedirs(service)
|
||||
if not os.path.exists(os.path.join(ARCHIVE_DIR, service)):
|
||||
os.makedirs(os.path.join(ARCHIVE_DIR, service))
|
||||
|
||||
if not os.path.exists(os.path.join(service, 'archive')):
|
||||
os.makedirs(os.path.join(service, 'archive'))
|
||||
if not os.path.exists(os.path.join(ARCHIVE_DIR, service, 'archive')):
|
||||
os.makedirs(os.path.join(ARCHIVE_DIR, service, 'archive'))
|
||||
|
||||
dump_index(links, service)
|
||||
check_dependencies()
|
||||
|
|
|
@ -26,6 +26,7 @@ FETCH_FAVICON = os.getenv('FETCH_FAVICON', 'True'
|
|||
SUBMIT_ARCHIVE_DOT_ORG = os.getenv('SUBMIT_ARCHIVE_DOT_ORG', 'True' ).lower() == 'true'
|
||||
RESOLUTION = os.getenv('RESOLUTION', '1440,900' )
|
||||
ARCHIVE_PERMISSIONS = os.getenv('ARCHIVE_PERMISSIONS', '755' )
|
||||
ARCHIVE_DIR = os.getenv('ARCHIVE_DIR', '')
|
||||
CHROME_BINARY = os.getenv('CHROME_BINARY', 'chromium-browser' ) # change to google-chrome browser if using google-chrome
|
||||
WGET_BINARY = os.getenv('WGET_BINARY', 'wget' )
|
||||
WGET_USER_AGENT = os.getenv('WGET_USER_AGENT', None)
|
||||
|
|
3
fetch.py
3
fetch.py
|
@ -7,6 +7,7 @@ from subprocess import run, PIPE, DEVNULL
|
|||
from parse import derived_link_info
|
||||
from config import (
|
||||
ARCHIVE_PERMISSIONS,
|
||||
ARCHIVE_DIR,
|
||||
CHROME_BINARY,
|
||||
FETCH_WGET,
|
||||
FETCH_WGET_REQUISITES,
|
||||
|
@ -261,7 +262,7 @@ def dump_website(link, service, overwrite=False, permissions=ARCHIVE_PERMISSIONS
|
|||
|
||||
print('[{green}+{reset}] [{timestamp} ({time})] "{title}": {blue}{base_url}{reset}'.format(**link, **ANSI))
|
||||
|
||||
out_dir = os.path.join(service, 'archive', link['timestamp'])
|
||||
out_dir = os.path.join(ARCHIVE_DIR, service, 'archive', link['timestamp'])
|
||||
if not os.path.exists(out_dir):
|
||||
os.makedirs(out_dir)
|
||||
|
||||
|
|
5
index.py
5
index.py
|
@ -7,6 +7,7 @@ from config import (
|
|||
INDEX_TEMPLATE,
|
||||
INDEX_ROW_TEMPLATE,
|
||||
ARCHIVE_PERMISSIONS,
|
||||
ARCHIVE_DIR,
|
||||
ANSI,
|
||||
chmod_file,
|
||||
)
|
||||
|
@ -33,10 +34,10 @@ def dump_index(links, service):
|
|||
'rows': article_rows,
|
||||
}
|
||||
|
||||
with open(os.path.join(service, 'index.html'), 'w', encoding='utf-8') as f:
|
||||
with open(os.path.join(ARCHIVE_DIR, service, 'index.html'), 'w', encoding='utf-8') as f:
|
||||
f.write(Template(index_html).substitute(**template_vars))
|
||||
|
||||
chmod_file(service, permissions=ARCHIVE_PERMISSIONS)
|
||||
chmod_file(os.path.join(ARCHIVE_DIR, service), permissions=ARCHIVE_PERMISSIONS)
|
||||
|
||||
print('[+] [{}] Created archive index with {}{}{} links.'.format(
|
||||
datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
|
|
Loading…
Reference in a new issue