1
0
Fork 0
archivebox/index.py

32 lines
988 B
Python
Raw Normal View History

import os
from datetime import datetime
from string import Template
from config import INDEX_TEMPLATE, INDEX_ROW_TEMPLATE
from parse import derived_link_info
def dump_index(links, service):
"""create index.html file for a given list of links and service"""
2017-07-04 07:26:46 -04:00
with open(INDEX_TEMPLATE, 'r', encoding='utf-8') as f:
index_html = f.read()
# TODO: refactor this out into index_template.html
2017-07-04 07:26:46 -04:00
with open(INDEX_ROW_TEMPLATE, 'r', encoding='utf-8') as f:
link_html = f.read()
article_rows = '\n'.join(
Template(link_html).substitute(**derived_link_info(link)) for link in links
)
2017-07-04 07:24:03 -04:00
template_vars = {
'num_links': len(links),
'date_updated': datetime.now().strftime('%Y-%m-%d'),
'time_updated': datetime.now().strftime('%Y-%m-%d %H:%M'),
'rows': article_rows,
}
2017-07-04 06:42:31 -04:00
with open(os.path.join(service, 'index.html'), 'w', encoding='utf-8') as f:
f.write(Template(index_html).substitute(template_vars))