-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_posts.py
25 lines (22 loc) · 942 Bytes
/
write_posts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import unidecode
def write_posts(content, url, save_path, title):
note_file_name = url.split('/')[4] + '.md'
date = content.get('date')
iframe = content.get('iframe')
note_title = str(title).replace('[', '').replace(']', '')\
.replace('\'', '').replace('\\', '').replace('+', 'with ')\
.replace(':', '').replace('\"', '').replace('||', '|').replace(')', '').replace('(', '')
with open(save_path/unidecode.unidecode(note_file_name), 'w', encoding='utf-8') as f:
f.write(f"---\n"
f"title: '{note_title}'\n"
f"date: {date}\n"
f"last_modified_at: {date}\n"
f"---\n")
for key, value in content.items():
if type(value) is list:
f.write(f"{key}: [[{']], [['.join(value)}]]")
else:
f.write(f"\n{iframe}")
break
f.close()
print(note_file_name)