From 60a34d2ef5a4a460a51d7d57f4b027f7622207d1 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Tue, 13 Oct 2020 23:11:47 +0200 Subject: [PATCH] store the files in a provided folder --- url2markdown/file.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/url2markdown/file.py b/url2markdown/file.py index 5c6f55d..4303d42 100644 --- a/url2markdown/file.py +++ b/url2markdown/file.py @@ -1,11 +1,20 @@ +import os.path import markdownify +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) + + def write_to_file(article, header): + file_path = _build_path(article.title) markdown = markdownify.markdownify(article.html, heading_style='ATX') - with open(str(article.title) + ".md", 'w') as f: + with open(file_path, 'w') as f: f.write(header) f.write('------') f.write('\n') - with open(str(article.title) + ".md", 'a') as f: + with open(file_path, 'a') as f: f.write(markdown)