2020-10-13 23:11:47 +02:00
|
|
|
import os.path
|
2020-10-12 22:25:47 +02:00
|
|
|
import markdownify
|
|
|
|
|
|
|
|
|
2020-10-13 23:11:47 +02:00
|
|
|
def _build_path(title):
|
|
|
|
ressources_folder = "~/03_documents/ressources/"
|
|
|
|
base_filename = str(title)
|
|
|
|
short_path = os.path.join(ressources_folder, base_filename + ".md")
|
|
|
|
return os.path.expanduser(short_path)
|
|
|
|
|
|
|
|
|
2020-10-12 22:25:47 +02:00
|
|
|
def write_to_file(article, header):
|
2020-10-13 23:11:47 +02:00
|
|
|
file_path = _build_path(article.title)
|
2020-10-13 21:17:05 +02:00
|
|
|
markdown = markdownify.markdownify(article.html, heading_style='ATX')
|
2020-10-13 23:11:47 +02:00
|
|
|
with open(file_path, 'w') as f:
|
2020-10-12 22:25:47 +02:00
|
|
|
f.write(header)
|
2020-10-13 21:18:04 +02:00
|
|
|
f.write('------')
|
|
|
|
f.write('\n')
|
2020-10-13 23:11:47 +02:00
|
|
|
with open(file_path, 'a') as f:
|
2020-10-12 22:25:47 +02:00
|
|
|
f.write(markdown)
|