1
0
Fork 0

Merge pull request #43 from m-rossi/custom_archive_dir

Add custom archive directory as configuration option.
This commit is contained in:
Nick Sweeting 2017-08-22 01:31:21 -04:00 committed by GitHub
commit a0c39bc725
4 changed files with 11 additions and 7 deletions

View file

@ -13,6 +13,7 @@ from index import dump_index
from fetch import dump_website from fetch import dump_website
from config import ( from config import (
ARCHIVE_PERMISSIONS, ARCHIVE_PERMISSIONS,
ARCHIVE_DIR,
ANSI, ANSI,
check_dependencies, 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)) print('[X] No links found in {}, is it a {} export file?'.format(export_file, service))
raise SystemExit(1) raise SystemExit(1)
if not os.path.exists(service): if not os.path.exists(os.path.join(ARCHIVE_DIR, service)):
os.makedirs(service) os.makedirs(os.path.join(ARCHIVE_DIR, service))
if not os.path.exists(os.path.join(service, 'archive')): if not os.path.exists(os.path.join(ARCHIVE_DIR, service, 'archive')):
os.makedirs(os.path.join(service, 'archive')) os.makedirs(os.path.join(ARCHIVE_DIR, service, 'archive'))
dump_index(links, service) dump_index(links, service)
check_dependencies() check_dependencies()

View file

@ -26,6 +26,7 @@ FETCH_FAVICON = os.getenv('FETCH_FAVICON', 'True'
SUBMIT_ARCHIVE_DOT_ORG = os.getenv('SUBMIT_ARCHIVE_DOT_ORG', 'True' ).lower() == 'true' SUBMIT_ARCHIVE_DOT_ORG = os.getenv('SUBMIT_ARCHIVE_DOT_ORG', 'True' ).lower() == 'true'
RESOLUTION = os.getenv('RESOLUTION', '1440,900' ) RESOLUTION = os.getenv('RESOLUTION', '1440,900' )
ARCHIVE_PERMISSIONS = os.getenv('ARCHIVE_PERMISSIONS', '755' ) 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 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_BINARY = os.getenv('WGET_BINARY', 'wget' )
WGET_USER_AGENT = os.getenv('WGET_USER_AGENT', None) WGET_USER_AGENT = os.getenv('WGET_USER_AGENT', None)

View file

@ -7,6 +7,7 @@ from subprocess import run, PIPE, DEVNULL
from parse import derived_link_info from parse import derived_link_info
from config import ( from config import (
ARCHIVE_PERMISSIONS, ARCHIVE_PERMISSIONS,
ARCHIVE_DIR,
CHROME_BINARY, CHROME_BINARY,
FETCH_WGET, FETCH_WGET,
FETCH_WGET_REQUISITES, 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)) 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): if not os.path.exists(out_dir):
os.makedirs(out_dir) os.makedirs(out_dir)

View file

@ -7,6 +7,7 @@ from config import (
INDEX_TEMPLATE, INDEX_TEMPLATE,
INDEX_ROW_TEMPLATE, INDEX_ROW_TEMPLATE,
ARCHIVE_PERMISSIONS, ARCHIVE_PERMISSIONS,
ARCHIVE_DIR,
ANSI, ANSI,
chmod_file, chmod_file,
) )
@ -33,10 +34,10 @@ def dump_index(links, service):
'rows': article_rows, '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)) 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( print('[+] [{}] Created archive index with {}{}{} links.'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'), datetime.now().strftime('%Y-%m-%d %H:%M:%S'),