def readNote(title): notes = loadNotes() try: found = next(note for note in notes if re.compile(title).match(note['title'])) print(chalk.bgGreen(f'title: {found["title"]}')) print(chalk.bgGreen(f'body: {", ".join(found["body"])}')) except Exception: print(chalk.bgRed('Note not found'))
def removeNote(title): # No argument, just word found in sys.argsv notes = loadNotes() notesToKeep = [note for note in notes if note['title'] != title] if len(notesToKeep) < len(notes): print(chalk.bgGreen(f'Removed note {title}')) json.dump(notesToKeep, open(os.path.join(os.path.dirname(__file__), 'todo.json'), 'w'), indent=4) else: print(chalk.bgRed('Note does not exist'))
def updateNote(title, body): # No argument, just word found in sys.argsv notes = loadNotes() # Follows the same logic as the removeNote function updatedNotes = [note for note in notes if note['title'] != title] if len(updatedNotes) < len(notes): print(chalk.bgGreen('Updated note')) updatedNotes.append({'title': title, 'body': body}) json.dump(updatedNotes, open(os.path.join(os.path.dirname(__file__), 'todo.json'), 'w'), indent=4) else: print(chalk.bgRed('Note does not exist'))
def addNote(title, body): # No argument, just word found in sys.argsv notes = loadNotes() found = [True for note in notes if note['title'] == title] if not found: notes.append({'title': title, 'body': [body]}) print(chalk.bgGreen('Added')) json.dump(notes, open(os.path.join(os.path.dirname(__file__), 'todo.json'), 'w'), indent=4) else: print(chalk.bgRed('Note taken'))
fh.write(f'* {item}\n') fh.write('\n') else: fh.write(f"* {note['body']}\n\n") def md_to_json(src=todo_md, clone=todo_json): with open(src) as fr: notes = [] note = {} for line in fr: if line.startswith('##'): title = line.strip().replace('## ', '') note = {'title': title, 'body': []} elif line.startswith('*'): bodyItem = line.strip().replace('* ', '') note['body'].append(bodyItem) elif line == '\n': notes.append(note) json.dump(notes, open(clone, 'w'), indent=4, sort_keys=False) if __name__ == '__main__': print(f'Calling main. Writing file copies to {os.path.abspath(".")}') try: json_to_md(src='../todo.json', clone='todo-copy.md') md_to_json(src='../todo.md', clone='todo-copy.json') except: print(chalk.bgRed('Error: Call from lib folder'))
) print(f'Git clone process in progress...') os.system(f'git clone {url}') elif args.pull: print( f'=========== Pull All Git Repos in home-user directory============' ) os.system( 'find $HOME -mindepth 1 -maxdepth 2 -type d -print -exec git -C {} pull \;' ) elif args.push: print(f'================= Push All Git Repos =============') os.system( "git config --global credential.helper 'cache --timeout 7200'") localRepoList = json.load( open( os.path.join(os.path.dirname(__file__), 'lib/localRepoList.json'))) for item, value in localRepoList.items(): print(f'\n>>>>>>> {item} <<<<<<<') os.system( f'git -C {value} add .; git -C {value} commit -m "gitpy to your rescue"; git -C {value} push' ) if len(sys.argv) > 1: gitList.main() gitTask(sys.argv[1]) else: print(chalk.bgRed('Not enough arguments'))