python tool: refactor
This commit is contained in:
parent
cb99880407
commit
30f9f786c2
|
@ -52,6 +52,14 @@ def savedata():
|
|||
else:
|
||||
writetextfile("data/local.json", json.dumps(data))
|
||||
|
||||
def loaddata():
|
||||
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"])
|
||||
return json.loads(readtextfile("data/backupdata.json"))
|
||||
else:
|
||||
return json.loads(readtextfile("data/local.json"))
|
||||
|
||||
def ask(question):
|
||||
answer = input(question)
|
||||
return answer == "y" or answer == "yes"
|
||||
|
@ -64,12 +72,7 @@ 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"))
|
||||
data = loaddata()
|
||||
|
||||
command = ""
|
||||
if len(sys.argv) > 1:
|
||||
|
@ -79,12 +82,10 @@ if len(sys.argv) > 1:
|
|||
|
||||
while not (command == "quit" or command == "exit" or command == "q"):
|
||||
|
||||
delete = False
|
||||
if command[0:3] == "rm ":
|
||||
index = int(command[3:])
|
||||
if ask("delete '" + data[index]["title"] + "'? "):
|
||||
data.remove(data[index])
|
||||
savedata()
|
||||
else:
|
||||
delete = True
|
||||
command = command[3:]
|
||||
|
||||
try:
|
||||
index = int(command)
|
||||
|
@ -92,7 +93,11 @@ while not (command == "quit" or command == "exit" or command == "q"):
|
|||
except:
|
||||
note = next((note for note in data if note["title"] == command), None)
|
||||
|
||||
if note:
|
||||
if delete:
|
||||
if note and ask("delete '" + note["title"] + "'? "):
|
||||
data.remove(note)
|
||||
savedata()
|
||||
elif note:
|
||||
editnote(note)
|
||||
else:
|
||||
if listnotes(command) == 0:
|
||||
|
|
Loading…
Reference in New Issue