def bump_flipped_card_timestamp(conn, cursor, card): flipped_card = card_repository.select_flipped_card(cursor, card) if flipped_card == None: return bumped_last_viewed = add_half_interval(flipped_card.last_viewed) bumped_flipped_card = Card( flipped_card.front, flipped_card.back, flipped_card.score, bumped_last_viewed ) card_repository.insert(conn, cursor, bumped_flipped_card) card_repository.delete(conn, cursor, flipped_card)
def new_cards(conn, cursor, two_way_card, single_line_mode, editor_mode): while True: card, two_way_card, single_line_mode, editor_mode = \ new_card(two_way_card, single_line_mode, editor_mode) if card == None: break card_repository.insert(conn, cursor, card) if two_way_card: flipped_card = Card( card.back, card.front, card.score, card.last_viewed ) card_repository.insert(conn, cursor, flipped_card) print_info('Saved.')
def iterate(conn, cursor, iterator, count): if count == 0: print_error('No results.') elif count == 1: print_info('[1 CARD.]') else: print_info('[{} CARDS.]'.format(count)) try: for card in iterator: print_instruction('[Ctrl+C to quit.]') updated_card, contents_changed = review_card(card) is_two_way_card = card_repository.is_two_way_card(cursor, card) if is_two_way_card and contents_changed: flipped_card_too = include_flipped_card() else: flipped_card_too = False if updated_card == None: card_repository.delete(conn, cursor, card) if flipped_card_too: card_repository.delete_flipped_card(conn, cursor, card) count -= 1 # Not an error, but I feel this should be red. print_error('DELETED.') table_is_empty = card_repository.check_if_empty(cursor) if table_is_empty: print_info('You have no more cards!') break else: if contents_changed: while True: card_repository.insert(conn, cursor, updated_card) if flipped_card_too: card_repository.insert_flipped_card(conn, cursor, updated_card) else: bump_flipped_card_timestamp(conn, cursor, card) print_instruction('Create another version based on this same card?') print_info('Protip: This is how you split one card into several cards.') while True: answer = colored_prompt('[y/n]: ') if answer in ['y', 'n']: break if answer == 'n': break else: updated_card = edit(card, flipped_card_too) card_repository.delete(conn, cursor, card) if flipped_card_too: card_repository.delete_flipped_card(conn, cursor, card) else: card_repository.insert(conn, cursor, updated_card) card_repository.delete(conn, cursor, card) bump_flipped_card_timestamp(conn, cursor, card) count -= 1 if count > 0: print_info('[{} MORE:]'.format(count)) except KeyboardInterrupt: print()