def listnotes(docopt_args): if docopt_args["--limit"]: limit = docopt_args["<items>"] insertvaluecache("list", str(limit), "") # Scrible().hasnext = "list" + str(limit) # print "next" + Scrible().hasnext note = NoteOperations() allnotes = note.viewall(limit) else: note = NoteOperations() allnotes = note.viewall() if len(allnotes) > 0: for item in allnotes: with indent(4, quote=' >'): noteid = item.get("_id", "") time = "["+ item.get("datecreated", "") + "]" noteids = "["+ str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET +" " + Back.BLUE + time + Back.RESET +"\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT +"\n\n"+ Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: with indent(4): puts(colored.yellow("Sorry, no notes present"))
def viewsinglenote(docopt_args): noteid = docopt_args["<note_id>"] if docopt_args["-m"]: note = NoteOperations() contents = note.view(noteid) else: note = NoteOperations() contents = note.view(noteid) with indent(4, quote=' >'): puts( colored.green(contents.get("title", "========NOT FOUND======="))) with indent(4): puts( colored.yellow(contents.get("body", "========NOT FOUND=======")))
def importnotes(docopt_args): filename = docopt_args["<filename>"] + ".csv" if os.path.isfile(filename): with open(filename, 'rb') as f: reader = csv.reader(f) for row in reader: title = row[0] body = row[1] time = row[2] note = NoteOperations() note.save(title=title, body=body) with indent(4, quote=' >'): puts(colored.green("Import successful")) note.synctocloud() else: with indent(4, quote=' >'): puts(colored.red("Sorry,the file does not exist"))
def createnewnote(docopt_args): notebody = "" if docopt_args["<note_title>"] and docopt_args["-m"]: with indent(4, quote=' >'): # puts( # colored.yellow('Type the body of the notes.Press "/pq" to save & exit')) print(Back.YELLOW + Fore.RED + 'Type the body of the notes' + Back.RESET + Fore.RESET + Style.BRIGHT + ' (Press ' + Back.YELLOW + Fore.RED + "/pq" + Back.RESET + Fore.RESET + ' to save & exit)' + Style.NORMAL + Fore.GREEN) sentinel = '/pq' # ends when this string is seen for line in iter(raw_input, sentinel): notebody += line + "\n" print(Fore.RESET) notetitle = docopt_args["<note_title>"] note = NoteOperations() note.save(title=notetitle, body=notebody) with indent(4, quote='√ '): puts(colored.green("Successfully saved")) note.synctocloud()
def nextquery(docopt_args): values = readvaluescache() if len(values) > 0: op = values.get("op", "") if op == "list": skip = values.get("skip", "") note = NoteOperations() allnotes = note.viewallskip(str(skip), str(skip)) if len(allnotes) > 0: insertvaluecache("list", str(int(skip) + int(skip)), "") for item in allnotes: noteid = item.get("_id", "") time = "["+ item.get("datecreated", "") + "]" noteids = "["+ str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET +" " + Back.BLUE + time + Back.RESET +"\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT +"\n\n"+ Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: with indent(4): puts(colored.yellow("End of notes")) elif op == "search": skip = values.get("skip", "") query = values.get("query", "") note = NoteOperations() allnotes = note.searchskip(query, str(skip), str(skip)) if len(allnotes) > 0: insertvaluecache("search", str(int(skip) + int(skip)), query) for item in allnotes: noteid = item.get("_id", "") time = "["+ item.get("datecreated", "") + "]" noteids = "["+ str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET +" " + Back.BLUE + time + Back.RESET +"\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT +"\n\n"+ Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: with indent(4): puts(colored.yellow("End of notes")) else: pass
def export(docopt_args): filename = docopt_args["<filename>"] finalfilepath = filename + ".csv" note = NoteOperations() allnotes = note.viewall() if len(allnotes) > 0: noteslist = [] for item in allnotes: title = item.get("title", "") body = item.get("body", "") timedate = item.get("datecreated", "") templist = [title, body, timedate] noteslist.append(templist) with open(finalfilepath, 'wb') as fp: a = csv.writer(fp, delimiter=',') a.writerows(noteslist) puts(colored.green( "Notes exported successfully to " + os.getcwd() + "/" + finalfilepath)) else: with indent(4): puts(colored.yellow("Sorry, no notes present"))
def listnotes(docopt_args): if docopt_args["--limit"]: limit = docopt_args["<items>"] insertvaluecache("list", str(limit), "") # Scrible().hasnext = "list" + str(limit) # print "next" + Scrible().hasnext note = NoteOperations() allnotes = note.viewall(limit) else: note = NoteOperations() allnotes = note.viewall() if len(allnotes) > 0: for item in allnotes: with indent(4, quote=' >'): noteid = item.get("_id", "") time = "[" + item.get("datecreated", "") + "]" noteids = "[" + str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET + " " + Back.BLUE + time + Back.RESET + "\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT + "\n\n" + Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: with indent(4): puts(colored.yellow("Sorry, no notes present"))
def searchnotes(docopt_args): query = docopt_args["<query_string>"] if docopt_args["--limit"]: limit = docopt_args["<items>"] insertvaluecache("search", str(limit), query) note = NoteOperations() notes = note.search(query, limit) else: note = NoteOperations() notes = note.search(query) if len(notes) > 0: for item in notes: noteid = item.get("_id", "") time = "[" + item.get("datecreated", "") + "]" noteids = "[" + str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET + " " + Back.BLUE + time + Back.RESET + "\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT + "\n\n" + Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: puts(colored.red("Sorry,the query does not match any notes"))
def searchnotes(docopt_args): query = docopt_args["<query_string>"] if docopt_args["--limit"]: limit = docopt_args["<items>"] insertvaluecache("search", str(limit), query) note = NoteOperations() notes = note.search(query, limit) else: note = NoteOperations() notes = note.search(query) if len(notes) > 0: for item in notes: noteid = item.get("_id", "") time = "["+ item.get("datecreated", "") + "]" noteids = "["+ str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET +" " + Back.BLUE + time + Back.RESET +"\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT +"\n\n"+ Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: puts(colored.red("Sorry,the query does not match any notes"))
def export(docopt_args): filename = docopt_args["<filename>"] finalfilepath = filename + ".csv" note = NoteOperations() allnotes = note.viewall() if len(allnotes) > 0: noteslist = [] for item in allnotes: title = item.get("title", "") body = item.get("body", "") timedate = item.get("datecreated", "") templist = [title, body, timedate] noteslist.append(templist) with open(finalfilepath, 'wb') as fp: a = csv.writer(fp, delimiter=',') a.writerows(noteslist) puts( colored.green("Notes exported successfully to " + os.getcwd() + "/" + finalfilepath)) else: with indent(4): puts(colored.yellow("Sorry, no notes present"))
def nextquery(docopt_args): values = readvaluescache() if len(values) > 0: op = values.get("op", "") if op == "list": skip = values.get("skip", "") note = NoteOperations() allnotes = note.viewallskip(str(skip), str(skip)) if len(allnotes) > 0: insertvaluecache("list", str(int(skip) + int(skip)), "") for item in allnotes: noteid = item.get("_id", "") time = "[" + item.get("datecreated", "") + "]" noteids = "[" + str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET + " " + Back.BLUE + time + Back.RESET + "\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT + "\n\n" + Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: with indent(4): puts(colored.yellow("End of notes")) elif op == "search": skip = values.get("skip", "") query = values.get("query", "") note = NoteOperations() allnotes = note.searchskip(query, str(skip), str(skip)) if len(allnotes) > 0: insertvaluecache("search", str(int(skip) + int(skip)), query) for item in allnotes: noteid = item.get("_id", "") time = "[" + item.get("datecreated", "") + "]" noteids = "[" + str(noteid) + "]" body = item.get("body", "") title = item.get("title", "========NOT FOUND=======") print(Fore.YELLOW + "===============================================" + Fore.RESET) print(Back.BLUE + noteids + Back.RESET + " " + Back.BLUE + time + Back.RESET + "\n\n" + Back.RED + title + Back.RESET + Style.BRIGHT + "\n\n" + Fore.GREEN + body + Fore.RESET + Style.NORMAL) print(Fore.YELLOW + "===============================================" + Fore.RESET) else: with indent(4): puts(colored.yellow("End of notes")) else: pass
def deletenote(docopt_args): noteid = docopt_args["<note_id>"] note = NoteOperations() if docopt_args["-a"]: puts("Are you sure you want to delete all notes? [" + colored.red("y") + "][" + colored.green("n") + "]") answer = raw_input(">") if answer == "y": status = note.delete(noteid, "all") else: return else: puts("Are you sure you want to delete note " + str(note.getnotetitle(noteid)) + "? [" + colored.red("y") + "][" + colored.green("n") + "]") answer = raw_input(">") if answer == "y": notetitle = note.getnotetitle(noteid) status = note.delete(noteid, "one") else: return if status > 0: with indent(4, quote=' √'): if docopt_args["-a"]: puts(colored.red("Successfully deleted all notes")) note = NoteOperations() note.deletenotesfromcloud() else: puts( colored.red("Successfully deleted note ") + colored.yellow(notetitle)) note = NoteOperations() note.synctocloud() else: with indent(4, quote=' √'): puts( colored.red("Sorry,the note with id ") + colored.green(noteid) + colored.red(" does not exist"))
def synctocloud(docopt_args): note = NoteOperations() note.synctocloud()
def deletenote(docopt_args): noteid = docopt_args["<note_id>"] note = NoteOperations() if docopt_args["-a"]: puts( "Are you sure you want to delete all notes? [" + colored.red("y") + "][" + colored.green("n") + "]") answer = raw_input(">") if answer == "y": status = note.delete(noteid, "all") else: return else: puts("Are you sure you want to delete note " + str(note.getnotetitle(noteid) ) + "? [" + colored.red("y") + "][" + colored.green("n") + "]") answer = raw_input(">") if answer == "y": notetitle = note.getnotetitle(noteid) status = note.delete(noteid, "one") else: return if status > 0: with indent(4, quote=' √'): if docopt_args["-a"]: puts(colored.red("Successfully deleted all notes")) note = NoteOperations() note.deletenotesfromcloud() else: puts(colored.red("Successfully deleted note ") + colored.yellow(notetitle)) note = NoteOperations() note.synctocloud() else: with indent(4, quote=' √'): puts(colored.red("Sorry,the note with id ") + colored.green(noteid) + colored.red(" does not exist"))