def loop(): clear_screen() options = OrderedDict({ 'A': Option('Add a bookmark', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'E': Option('Edit a bookmark', commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion), 'G': Option('Import GitHub stars', commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options), 'Q': Option('Quit', commands.QuitCommand()), }) print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose() _ = input('Press ENTER to return to menu')
def loop(): options = { 'A': Option('Add a book', commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, success_message='Bookmark added!'), 'B': Option('List bookmarks by date', commands.ListBookmarksCommand()), 'T': Option('List bookmarks by title', commands.ListBookmarksCommand(order_by='title')), 'E': Option('Edit a bookmark', commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, success_message='Bookmark updated!'), 'D': Option('Delete a bookmark', commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, success_message='Bookmark deleted!'), 'G': Option( 'Import Github stars', commands.ImportGithubStarsCommand(), prep_call=get_github_import_options, success_message='Imported {result} bookmarks from starred repos!'), 'Q': Option('Quit', commands.QuitCommand()) } print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose()
def edit_bookmark_data(): data = request.get_json() title = data['title'] url = data['url'] notes = data['notes'] bookmark = {"title": title, "url": url, "notes": notes} commands.EditBookmarkCommand() prep_call = bookmark return jsonify({'bookmark': bookmark}), 201
def get_new_bookmark_info(): data = request.get_json(force=True) bookmark_id = data['bookmark_id'] field = data['field'] new_value = data['new_value'] updated_data = { "id": bookmark_id, "update": { field: new_value }, } commands.EditBookmarkCommand() prep_call = updated_data return jsonify({'updated_data': updated_data}), 201
def loop(): clear_screen() # All steps for showing and selecting options # https://www.w3schools.com/python/python_dictionaries.asp options = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option("List bookmarks by title", commands.ListBookmarksCommand(order_by="title")), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, ), "G": Option( "Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options, ), "Q": Option("Quit", commands.QuitCommand()), } print_options(options) chosen_option = get_option_choice(options) clear_screen() chosen_option.choose() _ = input("Press ENTER to return to menu")
def test_print_options(self): optionsTest = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option("List bookmarks by title", commands.ListBookmarksCommand(order_by="title")), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, ), "G": Option( "Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options, ), "Q": Option("Quit", commands.QuitCommand()), } capturedOutput = io.StringIO() sys.stdout = capturedOutput print_options(optionsTest) sys.stdout = sys.__stdout__ print('Captured', capturedOutput.getvalue())
def test_option_choice_is_valid(self): optionsTest = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option("List bookmarks by title", commands.ListBookmarksCommand(order_by="title")), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_new_bookmark_info, ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, ), "G": Option( "Import GitHub stars", commands.ImportGitHubStarsCommand(), prep_call=get_github_import_options, ), "Q": Option("Quit", commands.QuitCommand()), } validChoice = option_choice_is_valid("A", optionsTest) self.assertEqual(validChoice, True, "Should be true if the value is true")
# Import starred repos from Github # need prep_call to get data from stdin. options = { "A": Option( "Add a bookmark", commands.AddBookmarkCommand(), prep_call=get_new_bookmark_data, success_message="Bookmark added!", ), "B": Option("List bookmarks by date", commands.ListBookmarksCommand()), "T": Option( "List bookmarks by title", commands.ListBookmarksCommand(order_by="title") ), "E": Option( "Edit a bookmark", commands.EditBookmarkCommand(), prep_call=get_bookmark_edit_info, success_message="Bookmark edited successfully!", ), "D": Option( "Delete a bookmark", commands.DeleteBookmarkCommand(), prep_call=get_bookmark_id_for_deletion, success_message="Bookmark deleted!", ), "G": Option( "Import Github stars", commands.ImportGithubStarsCommand(), prep_call=get_github_import_options, success_message="Import {result} bookmarks from Github scuuess!", ),