extend the header
This commit is contained in:
parent
ccda71858e
commit
e088d91fda
|
@ -17,4 +17,4 @@ def test_dict_to_string(create_article):
|
||||||
article.keywords = ['foo', 'bar', 'baz']
|
article.keywords = ['foo', 'bar', 'baz']
|
||||||
raw_header = header._build_header_dict(article)
|
raw_header = header._build_header_dict(article)
|
||||||
string = header._build_header_string(raw_header)
|
string = header._build_header_string(raw_header)
|
||||||
assert string =='- meta:\n - topics: [[foo]] [[bar]] [[baz]]\n - authors: [[Daniel Waldmeier]] [[Kei Zuefall]]\n'
|
assert string == '- meta:\n - topics: [[foo]] [[bar]] [[baz]]\n - date: [[2020-10-09]]\n - authors: [[Daniel Waldmeier]] [[Kei Zuefall]]\n - url: https://www.20min.ch/story/corona-zahlen-auf-einen-blick-803083076953\n'
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def _get_topics_from_cli():
|
def _get_topics_from_cli():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -5,6 +8,7 @@ def _get_topics_from_cli():
|
||||||
def _build_header_dict(article):
|
def _build_header_dict(article):
|
||||||
header = {}
|
header = {}
|
||||||
header['topics'] = _get_topics_from_cli()
|
header['topics'] = _get_topics_from_cli()
|
||||||
|
header['date'] = []
|
||||||
if article.authors:
|
if article.authors:
|
||||||
header['authors'] = article.authors
|
header['authors'] = article.authors
|
||||||
if article.keywords:
|
if article.keywords:
|
||||||
|
@ -14,17 +18,26 @@ def _build_header_dict(article):
|
||||||
header['topics'] = article.keywords
|
header['topics'] = article.keywords
|
||||||
if not header['topics']:
|
if not header['topics']:
|
||||||
header['topics'] = ['to_categorise']
|
header['topics'] = ['to_categorise']
|
||||||
|
if article.url:
|
||||||
|
header['url'] = article.url
|
||||||
|
if article.publish_date:
|
||||||
|
header['date'].append(article.publish_date.strftime('%Y-%m-%d'))
|
||||||
|
else:
|
||||||
|
header['date'].append(datetime.now().strftime('%Y-%m-%d'))
|
||||||
return header
|
return header
|
||||||
|
|
||||||
|
|
||||||
def _build_header_string(raw_header):
|
def _build_header_string(raw_header):
|
||||||
header = "- meta:\n"
|
header = "- meta:\n"
|
||||||
for key, value in raw_header.items():
|
for key, value in raw_header.items():
|
||||||
if key:
|
if value and type(value) == list:
|
||||||
content = ""
|
content = ""
|
||||||
for child in value:
|
for child in value:
|
||||||
content += " [[" + child + "]]"
|
content += " [[" + child + "]]"
|
||||||
header += " - {0}:".format(key) + content + "\n"
|
header += " - {0}:".format(key) + content + "\n"
|
||||||
|
elif value:
|
||||||
|
content = " " + str(value)
|
||||||
|
header += " - {0}:".format(key) + content + "\n"
|
||||||
return header
|
return header
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue