memos icon indicating copy to clipboard operation
memos copied to clipboard

如何快速导入通过flomo导出的数据?

Open WestXu opened this issue 2 years ago • 2 comments

https://help.flomoapp.com/basic/storage.html

flomo导出的数据是html格式的,如何导入到memos?

WestXu avatar Mar 31 '22 03:03 WestXu

https://help.flomoapp.com/basic/storage.html

flomo导出的数据是html格式的,如何导入到memos?

今天看到一个仓库 Flomo To Json。还没测试,不知道导出的json格式是否兼容

yylqing avatar May 18 '22 08:05 yylqing

https://help.flomoapp.com/basic/storage.html flomo导出的数据是html格式的,如何导入到memos?

今天看到一个仓库 Flomo To Json。还没测试,不知道导出的json格式是否兼容

尝试了一下发现有个小bug:部分memo输出的content会内容重复 例如a b会变成a a b b,需要注意一下

import json, csv, time
from datetime import datetime
def time2ts(x):
    return int(datetime.strptime(x, "%Y-%m-%d %H:%M:%S").timestamp())
res = [["id","creator_id","created_ts","updated_ts","row_status","content","visibility"]]
for idx,i in enumerate(json.load(open("myMemos.json"))):
    contents = i["content"]
    if not contents:
        continue
    c = [contents[0]]
    oldline = contents[0]
    for line in contents:
        if line==oldline:
            continue
        oldline = line
        c.append(line)
    res.append([1005+idx, 101, time2ts(i["time"]), time2ts(i["time"]), "NORMAL", "\n".join(c)+" ", "PRIVATE"])
csv.writer(open("out.csv", "w")).writerows(res)

我写了这个简单的python来转换为csv格式,然后用navicat手动导入了一下(从服务器复制db文件 navicat打开 对memo表导入 db文件复制到服务器替换) 效果还行 没有处理附件图片,其中1005需要改成当前表格最大id+1,101为authorid只有一个账号的话就是101,导入的content末尾加个空格是发现memos目前不会把末尾的tag认为是tag,除非加上了空格

zjuchenyuan avatar Jul 21 '22 11:07 zjuchenyuan

因为涉及到编码问题,我在这位作者的源代码基础上添加上了UTF-8编码参数,经测试使用没有问题


import json, csv, time
from datetime import datetime
def time2ts(x):
    return int(datetime.strptime(x, "%Y-%m-%d %H:%M:%S").timestamp())
res = [["id","creator_id","created_ts","updated_ts","row_status","content","visibility"]]
for idx,i in enumerate(json.load(open("myMemos.json",encoding="UTF-8"))):
    contents = i["content"]
    if not contents:
        continue
    c = [contents[0]]
    oldline = contents[0]
    for line in contents:
        if line==oldline:
            continue
        oldline = line
        c.append(line)
    res.append([1005+idx, 101, time2ts(i["time"]), time2ts(i["time"]), "NORMAL", "\n".join(c)+" ", "PRIVATE"])
csv.writer(open("out.csv", "w",encoding="UTF-8")).writerows(res)

Laifang avatar Sep 07 '22 00:09 Laifang