Last active
June 7, 2017 21:28
-
-
Save itsJlot/9a396e31559d3facee008d77dcdb8b65 to your computer and use it in GitHub Desktop.
Quick notes, allows for users to create and read notes in cmd help in application for help. Made using python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"help" : "Add a note by typing in one or more keywords, this is the 'tag' that you can use to find it.\nremove a note by putting a '/' in front, feel free to try it on deleteme right now, using '/deleteme'\nsearch for a note or just get its content using '?', when you specify a note it will return either nothing, indicating that it does not exist or the note you saved using that tag.\n you can also put a regex after the '?' to find all notetags that match that desciption.", | |
"deleteme" : "The help told you to delete me? Sure, go ahead, end my life. You dont have to feel bad."} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys,re | |
a = {} | |
out = "" | |
inp = "" | |
with open('db.json','r') as data: | |
a = json.load(data) | |
while True: | |
inp = input(out + '\nnext command:').lower() | |
if inp == 'end': | |
with open('db.json','w') as data: | |
json.dump(a,data) | |
sys.exit() | |
elif inp[0] == '/': | |
if inp[1:] in a: | |
del(a[inp[1:]]) | |
elif inp[0] == '?': | |
rall = list(a.keys()) | |
rshow = [] | |
if inp[1:] in a: | |
print(a[inp[1::]]) | |
else: | |
try: | |
rshow = [x for x in rall if re.search(inp[1:],x)] | |
print('Results:\n' + '\n'.join(rshow)) | |
except Exception: | |
print('invalid regex for the search entered.') | |
elif inp in a: | |
out = a[inp] | |
else: | |
a[inp] = input('What do you want to save here?') + '\n' | |
if a[inp] == '': | |
del(a[inp]) | |
out = '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment