url2markdown/url2markdown/header.py

35 lines
906 B
Python
Raw Normal View History

2020-10-12 15:17:54 +02:00
def _get_topics_from_cli():
pass
def _build_header_dict(article):
header = {}
header['topics'] = _get_topics_from_cli()
if article.authors:
header['authors'] = article.authors
if article.keywords:
2020-10-12 16:04:22 +02:00
if header['topics']:
header['topics'].append(article.keywords)
else:
header['topics'] = article.keywords
2020-10-12 15:17:54 +02:00
if not header['topics']:
header['topics'] = ['to_categorise']
return header
2020-10-12 16:04:22 +02:00
def _build_header_string(raw_header):
header = "- meta:\n"
for key, value in raw_header.items():
if key:
content = ""
for child in value:
content += " [[" + child + "]]"
header += " - {0}:".format(key) + content + "\n"
return header
def build_header(article):
raw_header = _build_header_dict(article)
header = _build_header_string(raw_header)
return header