klwb
关注
121719 号成员,2023-12-11 14:30:46 加入
40
个人主页 浏览
1h4m
在线时长
  • 如何修改创建时间?

    2024-02-05 17:25

    对的,大量笔记的话就要自动化了,印象导出的文件 enex 是 xml 格式里面有所有笔记的 index,后面我也写了个方法,自动索引对应

    import xml.etree.ElementTree as ET
    
    def parse_xml_iterative(xml_file):
        notes_data = []
      
        context = ET.iterparse(xml_file, events=('start', 'end'))
        context = iter(context)
        event, root = next(context)  # 获取根节点
    
        for event, elem in context:
            if event == 'end' and elem.tag == 'note':
                title = elem.find('./title').text
                created = elem.find('./created').text
                updated = elem.find('./updated').text
    
                notes_data.append({
                    'title': title,
                    'created': created.replace('T','').replace('Z',''),
                    'updated': updated.replace('T','').replace('Z','')
                })
    
                root.clear()  # 清除已处理的元素,减少内存占用
    
        return notes_data
    
  • 是否提供文档级“加密”以保护隐私?(含投票)

    2024-01-04 00:51

    文档、笔记本、ui 加密没有意义,本地数据文件夹都是明文

    本地数据文件夹或.sy 级别的加密对思源客户端的性能是个很大的压力,以后做不到秒开了。

    但其实有个中间状态,仅加密需要加密的。这样大部分不加密不影响性能,少部分加密又能兼顾隐私

  • 希望能增加笔记本加密或隐藏功能

    2024-01-04 00:38

    本机路径是明文,只要有访问当前设备权限的应用或者人都能拿到 data 目录,里面的.sy 文件都是明文。稍微有点技术基础的人都能拿到。这个确实也是一个问题。ios 有沙箱还好,其他 android windows mac 等路径任意有文件读写权限的应用都能访问,就是怕别有用心的人或者应用读取

  • 如何修改创建时间?

    2023-12-19 23:06

    正常的,不过搞之前建议还是导出备份一下

  • 如何修改创建时间?

    2023-12-19 18:06

    文件 id 要改,里面内容的 id 也要改,一致的话不会有问题

  • 如何修改创建时间?

    2023-12-19 18:05

    感谢各路大神回复啊,我写了个脚本可以批量修改创建时间,如果需要可以交流使用:)

    改完要确实要重建索引:)

    ```python
    import os
    import json
    import re
    
    def process_files(directory_path):
        mapping_array = []
    
        # 遍历 SiYuan/data 目录下所有 .sy 结尾的文件
        for root, dirs, files in os.walk(directory_path):
            for file in files:
                if file.endswith(".sy"):
                    file_path = os.path.join(root, file)
              
                    # 提取文件名中的时间和唯一码
                    match = re.match(r'(\d+)-(\w+)\.sy', file)
                    if match:
                        create_time, file_key = match.groups()
                    else:
                        continue
              
                    # 读取 JSON 文件内容,根据这个title你可以确定笔记创建时间(从其他笔记应用导过来)
                    with open(file_path, 'r', encoding='utf-8') as json_file:
                        data = json.load(json_file)
                        title_content = data.get("Properties", {}).get("title", "")
    
                    # 生成映射数组
                    mapping = {
                        'key': file_key,
                        'title': title_content,
                        'real_create_time': '',
                        'filePath': file_path
                    }
    
                    mapping_array.append(mapping)
    
        # 将映射数组保存到 mappings.txt 文件中
        with open('mappings.txt', 'w', encoding='utf-8') as mappings_file:
            json.dump(mapping_array, mappings_file, ensure_ascii=False, indent=2)
    
    
    
    
    # 替换你思源本地数据绝对路径
    directory_path = '/Users/yourdir/SiyuanTestCanDelete/data'
    process_files(directory_path)
    

    根据你导入的笔记 文本编辑器打开 mappings.txt 文件手动修改,依据 20231219164139 这样的格式给 real_create_time 赋值即可

    import json
    import re
    import os
    
    def replace_time_in_files(mapping_array):
        for mapping in mapping_array:
            # 只有当 real_create_time 不为空时才执行替换操作
            if mapping['real_create_time']:
                old_file_path = mapping['filePath']
    
                # 读取旧文件内容
                with open(old_file_path, 'r', encoding='utf-8') as old_file:
                    file_content = old_file.read()
    
                    # 替换文件内容中的时间戳
                    new_file_content = re.sub(
                        r'(?<="ID":")(\d{14})|(?<="id":")(\d{14})|(?<="updated":")(\d{14})',
                        mapping['real_create_time'],
                        file_content
                    )
    
                # 构造新文件名
                old_dir, old_file_name = os.path.split(old_file_path)
                new_file_name = mapping['real_create_time']+'-'+mapping['key']+'.sy'
          
                new_file_name = os.path.join(old_dir, new_file_name)
          
                # print(old_dir,old_file_path,new_file_name,new_file_content,sep='\r\n\r\n')
          
                # 写入新文件
                with open(new_file_name, 'w', encoding='utf-8') as new_file:
                    new_file.write(new_file_content)
    
                # 删除旧文件 此处先保留以备恢复
                # os.remove(old_file_path)
    
    
    # 读取映射数组
    with open('mappings.txt', 'r', encoding='utf-8') as mappings_file:
        mappings = json.load(mappings_file)
    
    # 第三步:替换文件名和文件内容中的时间
    replace_time_in_files(mappings)