python tool: added local mode
This commit is contained in:
parent
4852d27da7
commit
897e6f587c
|
@ -43,16 +43,15 @@ def editnote(note):
|
||||||
data.remove(note)
|
data.remove(note)
|
||||||
data.insert(0, note)
|
data.insert(0, note)
|
||||||
|
|
||||||
|
if settings["mode"] == "remote":
|
||||||
writetextfile("data/data.json", json.dumps(data))
|
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"]);
|
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")
|
newdata = readtextfile("data/data.acs")
|
||||||
|
|
||||||
postdata = "action=push&password=" + settings["password"] + "&data=" + urllib.parse.quote_plus(newdata)
|
postdata = "action=push&password=" + settings["password"] + "&data=" + urllib.parse.quote_plus(newdata)
|
||||||
|
|
||||||
writetextfile("data/postdata", postdata)
|
writetextfile("data/postdata", postdata)
|
||||||
|
|
||||||
subprocess.call(["curl", "-s", "-X", "POST", "-d", "@data/postdata", settings["url"] + "/handler.php"])
|
subprocess.call(["curl", "-s", "-X", "POST", "-d", "@data/postdata", settings["url"] + "/handler.php"])
|
||||||
|
else:
|
||||||
|
writetextfile("data/local.json", json.dumps(data))
|
||||||
else:
|
else:
|
||||||
listnotes()
|
listnotes()
|
||||||
print("no change")
|
print("no change")
|
||||||
|
@ -62,10 +61,12 @@ settings = json.loads(readtextfile("settings.json"))
|
||||||
if os.path.isfile("data/backupdata.acs"):
|
if os.path.isfile("data/backupdata.acs"):
|
||||||
os.remove("data/backupdata.acs")
|
os.remove("data/backupdata.acs")
|
||||||
|
|
||||||
subprocess.call(["curl", "-s", "-X", "POST", "-F", "action=fetch", "-F", "password=" + settings["password"], "-o", "data/backupdata.acs", settings["url"] + "/handler.php"])
|
if settings["mode"] == "remote":
|
||||||
subprocess.call([settings["commands"]["gpg"], "-q", "--yes", "--output", "data/backupdata.json", "--decrypt", "data/backupdata.acs"])
|
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"))
|
data = json.loads(readtextfile("data/backupdata.json"))
|
||||||
|
else:
|
||||||
|
data = json.loads(readtextfile("data/local.json"))
|
||||||
|
|
||||||
command = ""
|
command = ""
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
@ -73,7 +74,6 @@ if len(sys.argv) > 1:
|
||||||
if command.startswith("notes://"):
|
if command.startswith("notes://"):
|
||||||
command = urllib.parse.unquote(command[8:-1])
|
command = urllib.parse.unquote(command[8:-1])
|
||||||
|
|
||||||
|
|
||||||
while not (command == "quit" or command == "exit" or command == "q"):
|
while not (command == "quit" or command == "exit" or command == "q"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -7,5 +7,6 @@
|
||||||
"editor": ["vim"],
|
"editor": ["vim"],
|
||||||
"gpg": "gpg",
|
"gpg": "gpg",
|
||||||
"diff": ["diff", "--color"]
|
"diff": ["diff", "--color"]
|
||||||
}
|
},
|
||||||
|
"mode": "remote"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue