extend the header

This commit is contained in:
Andreas Zweili 2020-10-12 21:49:03 +02:00
parent ccda71858e
commit e088d91fda
2 changed files with 16 additions and 3 deletions

View File

@ -17,4 +17,4 @@ def test_dict_to_string(create_article):
article.keywords = ['foo', 'bar', 'baz']
raw_header = header._build_header_dict(article)
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'

View File

@ -1,3 +1,6 @@
from datetime import datetime
def _get_topics_from_cli():
pass
@ -5,6 +8,7 @@ def _get_topics_from_cli():
def _build_header_dict(article):
header = {}
header['topics'] = _get_topics_from_cli()
header['date'] = []
if article.authors:
header['authors'] = article.authors
if article.keywords:
@ -14,17 +18,26 @@ def _build_header_dict(article):
header['topics'] = article.keywords
if not header['topics']:
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
def _build_header_string(raw_header):
header = "- meta:\n"
for key, value in raw_header.items():
if key:
if value and type(value) == list:
content = ""
for child in value:
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