diff options
Diffstat (limited to 'goatNote.py')
-rw-r--r-- | goatNote.py | 111 |
1 files changed, 81 insertions, 30 deletions
diff --git a/goatNote.py b/goatNote.py index efd62c3..173ae0c 100644 --- a/goatNote.py +++ b/goatNote.py @@ -1,6 +1,6 @@ from enum import Enum import re - +import os # Assigning numbers to types of data class tokenTypes (Enum): @@ -19,13 +19,13 @@ class date: self.month = int(dateString[1]) self.day = int(dateString[2]) -# Tokenizing -# TODO ADD SPACES TO HEADING TODO -#regEX + def asString(self): + return f"{str(self.year)}.{str(self.month):{'0'}>2}.{str(self.day):{'0'}>2}" + +# Tokenizing with regex def tokenize(file: str): headingRe = r"\s*\*\s*([A-z0-9]+)\s*\*\s*\[(\d\d\d\d[.]\d\d[.]\d\d)\]\s*{(TO[.]DO|DONE)}\s*" bulletPointRe = r"-\s*((\s|[A-z0-9])+)\s*" - unprocessed = [] end = False @@ -36,6 +36,7 @@ def tokenize(file: str): if heading != None: unprocessed.append(heading.group()) file = file[heading.span()[1]:] + elif bulletPoint != None: unprocessed.append(bulletPoint.group()) file = file[bulletPoint.span()[1]:] @@ -68,48 +69,98 @@ def tokenize(file: str): return values, types +def printHeading(values, i): + if values[i + 2]: + toDoString = "DONE" + else: + toDoString = "TO.DO" + print(f"{values[i]:{" "}<30}| {values[i+1].asString()} | {toDoString}") + +def view(values, types): + output = "" + for i in range(len(values)): + if types[i] == tokenTypes.HEADING: + output += values[i] + "|" + if types[i] == tokenTypes.DATE: + output += values[i].asString() + "|" + if types[i] == tokenTypes.TODO: + if not values[i]: + output += "DONE\n" + else: + output += "TO.DO\n" + if types[i] == tokenTypes.BULLETPOINT: + output += str(values[i][0]) + return output + +def outputGoatNote(values, types): + output = "" + for i in range(len(values)): + if types[i] == tokenTypes.HEADING: + output += "* " + values[i] + " * " + if types[i] == tokenTypes.DATE: + output += "[" + values[i].asString() + "] " + if types[i] == tokenTypes.TODO: + if not values[i]: + output += "{DONE}\n" + else: + output += "{TO.DO}\n" + if types[i] == tokenTypes.BULLETPOINT: + output += "- " + str(values[i][0]) + return output -# Put user into shell then ask for which file to read from +# MAIN CODE STARTS HERE Put user into shell then ask for which file to read from fileName = input("Which GOATED file do you wanna read?? \n") -if fileName == "": - fileName = "~/.global.gn" - +if fileName == "": fileName = f"{os.environ["HOME"]}/.global.gn" if ".gn" not in fileName: print("That's not a goatNote file! Silly goose! Automatically putting into the global file!") - fileName = "~/.global.gn" + fileName = f"{os.environ["HOME"]}/.global.gn" -try: - file = open(fileName, "r").read() +try: file = open(fileName, "r") except: print("ABORT MISSION (couldn't open file)", fileName, "does not exist") exit(1) -values, types = tokenize(file) +values, types = tokenize(file.read()) +file.close() +file = open(fileName, "w") # Drop user into a shell -print("enter one of the following commands: list, toggle, change date, view, formatting help, or type close to exit program") +print("enter one of the following commands: list, toggle, view, help, or type close to exit program") +line = input(": ").lower().split(" ") -line = input(": ") +while line[0] != "close": + if line[0] == "list": + for i in range(len(types)): + if types[i] == tokenTypes.HEADING: + printHeading(values, i) -while line != "close": - if line == "list": + elif line[0] == "toggle": for i in range(len(types)): if types[i] == tokenTypes.HEADING: - print(values[i]) - - elif line == "toggle": - print("You said toggle :(") - elif line == "change date": - print("CHANGE DATEEE") - elif line == "view": - print("look at me (view)") - elif line == "formatting help": - print("you need help? loser.") + if values[i] == line[1]: + values[i+2] = not values[i+2] + break + + elif line[0] == "view": + print(view(values, types)) + + elif line[0] == "help": + if len(line) == 1: print("enter one of the following commands following the word \"help\": list, toggle, view, formatting, or type close to exit program") + elif line[1] == "list": print("Typing the list command....") + elif line[1] == "toggle": print("TogglE") + elif line[1] == "view": print("look") + elif line[1] == "formatting": print("read") + else: print("enter one of the following commands following the word \"help\": list, toggle, view, formatting, or type close to exit program") + + elif line[0] == "save": + file.write(outputGoatNote(values, types)) + file.flush() + else: print("Invalid command :(") - line = input(": ") - -print("byee(closing file)") + line = input(": ").lower().split(" ") +print("byee(closing program)") +file.close() |