python tool: added command to delete note
This commit is contained in:
parent
230582920e
commit
cb99880407
|
@ -6,10 +6,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
abspath = os.path.abspath(__file__)
|
|
||||||
dname = os.path.dirname(abspath)
|
|
||||||
os.chdir(dname)
|
|
||||||
|
|
||||||
def listnotes(filter = ""):
|
def listnotes(filter = ""):
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for i in reversed(range(len(data))):
|
for i in reversed(range(len(data))):
|
||||||
|
@ -36,13 +32,16 @@ def editnote(note):
|
||||||
newcontent = readtextfile("data/note.md")
|
newcontent = readtextfile("data/note.md")
|
||||||
|
|
||||||
if newcontent != content:
|
if newcontent != content:
|
||||||
|
|
||||||
subprocess.call(settings["commands"]["diff"] + ["data/backupnote.md", "data/note.md"])
|
subprocess.call(settings["commands"]["diff"] + ["data/backupnote.md", "data/note.md"])
|
||||||
|
|
||||||
note["content"] = newcontent
|
note["content"] = newcontent
|
||||||
data.remove(note)
|
data.remove(note)
|
||||||
data.insert(0, note)
|
data.insert(0, note)
|
||||||
|
savedata()
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("no change")
|
||||||
|
|
||||||
|
def savedata():
|
||||||
if settings["mode"] == "remote":
|
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"]);
|
||||||
|
@ -52,9 +51,14 @@ def editnote(note):
|
||||||
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:
|
else:
|
||||||
writetextfile("data/local.json", json.dumps(data))
|
writetextfile("data/local.json", json.dumps(data))
|
||||||
else:
|
|
||||||
print("no change")
|
|
||||||
|
|
||||||
|
def ask(question):
|
||||||
|
answer = input(question)
|
||||||
|
return answer == "y" or answer == "yes"
|
||||||
|
|
||||||
|
abspath = os.path.abspath(__file__)
|
||||||
|
dname = os.path.dirname(abspath)
|
||||||
|
os.chdir(dname)
|
||||||
settings = json.loads(readtextfile("settings.json"))
|
settings = json.loads(readtextfile("settings.json"))
|
||||||
|
|
||||||
if os.path.isfile("data/backupdata.acs"):
|
if os.path.isfile("data/backupdata.acs"):
|
||||||
|
@ -75,6 +79,13 @@ if len(sys.argv) > 1:
|
||||||
|
|
||||||
while not (command == "quit" or command == "exit" or command == "q"):
|
while not (command == "quit" or command == "exit" or command == "q"):
|
||||||
|
|
||||||
|
if command[0:3] == "rm ":
|
||||||
|
index = int(command[3:])
|
||||||
|
if ask("delete '" + data[index]["title"] + "'? "):
|
||||||
|
data.remove(data[index])
|
||||||
|
savedata()
|
||||||
|
else:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
index = int(command)
|
index = int(command)
|
||||||
note = data[index]
|
note = data[index]
|
||||||
|
@ -84,11 +95,8 @@ while not (command == "quit" or command == "exit" or command == "q"):
|
||||||
if note:
|
if note:
|
||||||
editnote(note)
|
editnote(note)
|
||||||
else:
|
else:
|
||||||
cnt = listnotes(command)
|
if listnotes(command) == 0:
|
||||||
|
if ask("create '" + command + "'? "):
|
||||||
if cnt == 0:
|
|
||||||
answer = input("create '" + command + "'? ")
|
|
||||||
if answer == "y" or answer == "yes":
|
|
||||||
note = {
|
note = {
|
||||||
"title": command,
|
"title": command,
|
||||||
"content": "---\ntitle: " + command + "\ndate: " + time.strftime("%Y-%m-%d") + "\ntags: \n---\n\n"
|
"content": "---\ntitle: " + command + "\ndate: " + time.strftime("%Y-%m-%d") + "\ntags: \n---\n\n"
|
||||||
|
|
Loading…
Reference in New Issue