Created
October 10, 2023 02:51
-
-
Save cztchoice/694a99ee8d8c3f3c4fea1261a90428f5 to your computer and use it in GitHub Desktop.
flomo 导出文件转markdown,方便导入obsidian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import markdownify | |
import re | |
import datetime | |
from bs4 import BeautifulSoup | |
with open("index.html") as f: | |
html = f.read() | |
soup = BeautifulSoup(html, 'html.parser') | |
memos = soup.find_all('div', class_='memo') | |
for memo in memos: | |
time = memo.find('div', class_='time').text | |
content = memo.find('div', class_='content') | |
# print(content) | |
# 清理内容 | |
markdown_text = markdownify.markdownify(str(content)) | |
# print(markdown_text) | |
# 输出Markdown | |
dt = datetime.datetime.strptime(time, '%Y-%m-%d %H:%M:%S') | |
date = dt.date() | |
file_name = str(date) + '.md' | |
print(file_name) | |
# 需要先创建 flomo目录,最终按照文件日期创建相关导出文件 | |
file_path = "flomo/" + file_name | |
with open(file_path, 'a') as f: | |
f.write(f'{markdown_text}\n[{time}]\n\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment