一直以来都在使用memos记录随笔,但是由于各种原因,再三考虑还是将其转换为本地随笔。正好,obsidian上有一款和memos或者是flomo很像的插件——Thino。
Thino 可以直接在obsidian的社区直接下载安装。
Thino提供了从html文件导入数据的方式,flomo的用户可以直接使用flomo导出的html文件直接导入数据。
但是,memos并没有提供直接的数据导出功能,但好在,memos是通过数据库文件保存数据的。
memos的数据库保存地址可以通过docker 命令
docker inspect +你的memos名
找到_data文件夹,memos_prod.db
就是你的数据库文件。
将它下载到桌面。
我这里用的是xshell,其他软件也行,只要将它下载下来就行。
到现在为止,你就获得了一份数据库文件,你可以开始对你的数据为所欲为了🤔。
之后用python脚本对数据库文件进行操作,生成我们想要的html文件即可。
以下是生成代码:
import sqlite3
import os
from pathlib import Path
#数据库文件路径
db_path = 'C:/Users/你的用户名/Desktop/memos_prod.db'
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
#获取数据
cursor.execute('SELECT created_ts FROM memo')
time_rows = cursor.fetchall()
cursor.execute('SELECT content FROM memo')
text_rows = cursor.fetchall()
#初始化 HTML 字符串
html = '<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>Database Data</title>\n</head>\n<body>\n'
for time_tuple, (text_data,) in zip(time_rows, text_rows):
time_str = time_tuple[0]
if isinstance(text_data, str):
text_with_br = text_data.replace('\n', '<br>')
else:
text_with_br = 'Error: Non-string data in content column'
# 构建包含 <div> 的 HTML 字符串
div_html = f'<div class="memo">\n'
div_html += f'<div class="time">{time_str}</div>\n'
div_html += f'<div class="content"> {text_with_br}</div>\n'
div_html += f'<div class="files"></div>\n'
div_html += '</div>\n\n'
html += div_html
# 结束 HTML 文档
html += '</div>\n'
html += '</body>\n</html>'
desktop_path = Path.home() / "Desktop"
file_path = desktop_path / 'database_data.html'
with open(file_path, 'w', encoding='utf-8') as f:
f.write(html)
# 关闭数据库连接
conn.close()
print("HTML file saved.")
然后直接运行即可
你就会收获一份html文件
回到本文开头,点击导入,选择你的html文件,打击打开,就可以开始欣赏数据不断加载的美了。