前言
思源笔记是一款本地笔记为主的软件,其目前提供了148元/year的付费同步功能,但对于21世纪中国难民而言还是太贵啦。
条件允许的同学还是使用官方的同步,支持下作者。

所以,就在思考有没有白嫖的一种方法,能同步且不要付费呢。
网上有些使用云盘自动同步,但可能导致数据丢失。
这里提供方法:
笔记通过小软件的方式进行自动同步到git。
这个[siyuansyntogit]小软件基于python开发,我只在win10上进行过测试,下方有源码及exe提供,诸君自取。
https://gitee.com/kingstacker/siyuansyntogit

笔者对python语言并不熟悉,这是第一个demo,当前对于我已然够用,当然你可以自行进行更改。
软件及环境:
win10、思源笔记v2.4.7、siyuansyntogit、git、gitee网站
流程
(1)软件支持功能:
>目录正确性判断
>网络连接线判断,打开软件后,检测到电脑联网后会自动拉取远程文件同步
>检测思源笔记开关状态
>思源笔记软件关闭则自动提交git同步
>小软件运行后默认最小化 窗口运行

(2)确保你使用过Git,Git使用不再此文说明。软件放置路径跟思源笔记的data路径在同一层级。git工程也在这一层级。

.gitignore文件内容参考:避免其他文件夹同步,这里只会同步data文件夹。思源笔记的笔记内容是存放在data文件夹中的。
conf/ history/ temp/ *exe
(3)确保已经进行了初次git提交,确保环境一切正常。enjoy it。
(4)你也可以把小软件开机自启:
参考:https://zhuanlan.zhihu.com/p/446167633
(4.1)创建小软件的快捷方式。

(4.2)快捷方式拖入:win+R打开打开对话框输入shell:startup,进入启动文件夹

(5)小软件运行界面图示:小软件打开默认最小化运行。

检测到思源笔记软件关闭,则自动提交同步。

这里使用gitee作为远程仓库,可以看到版本已经提交。

(6)源码参考:你可以进行任意更改,希望我的工作对你有所帮助。
import os import sys import ctypes import time import psutil from subprocess import call home_dir = os.getcwd() #获得当前路径 choice_list = ['上传','下载'] def git_update(): os.chdir(home_dir) git_add_cmd = "git add ." git_commit_cmd = "git commit -m {}".format(gitdate) git_push_cmd = "git push origin master" call( git_add_cmd + "&&" + git_commit_cmd + "&&" + git_push_cmd, shell=True ) def git_get(): os.chdir(home_dir) git_pull_cmd = "git pull origin master" call( git_pull_cmd, shell=True ) def is_process_running(process_name): pl = psutil.pids() for pid in pl: if psutil.Process(pid).name() == process_name: return True else: return False if __name__ == "__main__": ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 6) print("---------------------------------------------------") print("欢迎使用 SiYuan Auto Backup,poweredBy kingstacker!") print("---------------------------------------------------") print("程序当前运行路径:") print(home_dir) time.sleep(0.5) print("----------------") print("检查程序执行路径是否正确中...") dir_status = int(os.path.exists(home_dir+'data')) if dir_status == 1: print("程序执行路径正确.") pass else: print("未发现当前路径存在data文件夹,请确认!") os.system("pause") sys.exit() eth_exit_code = 1 print("----------------") print('检查网络连接状态中,请等待...') status_befor = 0; auto_pull_status = 0; while True: if eth_exit_code == 1: # eth_exit_code = int(os.system('ping www.baidu.com > /dev/null')) eth_exit_code = int(os.system('ping www.baidu.com')) else: pass if eth_exit_code == 1: print('没联网,确认你的网络连接状态.') time.sleep(2) while True: gitdate = time.strftime("%Y-%m-%d/%H-%M-%S/%A", time.localtime()) if eth_exit_code: break if auto_pull_status == 0: print("----------------") print("拉取远程文件中...") git_get() print("拉取远程文件完成!") print("----------------") time.sleep(2) try: siyuan_program_status = int(is_process_running("SiYuan.exe")) # 查看思源软件是否打开 except: pass else: pass if status_befor == 0 and siyuan_program_status == 1: print("----------------") print("发现思源软件已打开,等待软件关闭...") if status_befor == 1 and siyuan_program_status == 0: print("----------------") print("发现思源软件已关闭,备份笔记到云端中...") print("请等待...") print("拉取远程文件更新确认中...") git_get() print("正在提交笔记...") git_update() print("提交备份已完成!") print("当前备份时间点:",gitdate) print("----------------") status_befor = int(siyuan_program_status) auto_pull_status = 1;
以上。