python tool: added local mode

This commit is contained in:
quenousimporte 2023-09-14 11:03:04 +02:00
parent 4852d27da7
commit 897e6f587c
2 changed files with 17 additions and 16 deletions

View File

@ -43,16 +43,15 @@ def editnote(note):
data.remove(note)
data.insert(0, note)
if settings["mode"] == "remote":
writetextfile("data/data.json", json.dumps(data))
subprocess.call([settings["commands"]["gpg"], "-q", "--encrypt", "--yes", "--trust-model", "always", "--output", "data/data.acs", "--armor", "-r", settings["gpguser"], "data/data.json"]);
newdata = readtextfile("data/data.acs")
postdata = "action=push&password=" + settings["password"] + "&data=" + urllib.parse.quote_plus(newdata)
writetextfile("data/postdata", postdata)
subprocess.call(["curl", "-s", "-X", "POST", "-d", "@data/postdata", settings["url"] + "/handler.php"])
else:
writetextfile("data/local.json", json.dumps(data))
else:
listnotes()
print("no change")
@ -62,10 +61,12 @@ settings = json.loads(readtextfile("settings.json"))
if os.path.isfile("data/backupdata.acs"):
os.remove("data/backupdata.acs")
if settings["mode"] == "remote":
subprocess.call(["curl", "-s", "-X", "POST", "-F", "action=fetch", "-F", "password=" + settings["password"], "-o", "data/backupdata.acs", settings["url"] + "/handler.php"])
subprocess.call([settings["commands"]["gpg"], "-q", "--yes", "--output", "data/backupdata.json", "--decrypt", "data/backupdata.acs"])
data = json.loads(readtextfile("data/backupdata.json"))
else:
data = json.loads(readtextfile("data/local.json"))
command = ""
if len(sys.argv) > 1:
@ -73,7 +74,6 @@ if len(sys.argv) > 1:
if command.startswith("notes://"):
command = urllib.parse.unquote(command[8:-1])
while not (command == "quit" or command == "exit" or command == "q"):
try:

View File

@ -7,5 +7,6 @@
"editor": ["vim"],
"gpg": "gpg",
"diff": ["diff", "--color"]
}
},
"mode": "remote"
}