def review_card(card): print(card.front) colored_getpass('[Enter to flip the card.]') print(card.back) while True: score = colored_prompt("[Score yourself from 0 to 5, or enter 'o' for options:] ") if score == 'o': return menu(card) if score.isdigit() and int(score) in list(range(6)): break contents_changed = False last_viewed = get_timestamp() updated_card = Card( card.front, card.back, score, last_viewed ) return updated_card, contents_changed
def parse_edits(lines, tags): if not all([x in lines for x in tags]): print_error('Error: The lines "{}", "{}", and/or "{}" are messed up.'.format(*tags)) colored_getpass('Hit Enter to start over.') return None, None front_index = lines.index(tags[0]) back_index = lines.index(tags[1]) score_index = lines.index(tags[2]) front_lines = lines[front_index + 1:back_index] back_lines = lines[back_index + 1:score_index] front = '\n'.join(front_lines) back = '\n'.join(back_lines) last_viewed = get_timestamp() if len(lines) < score_index + 2: print_error('Error: No score.') colored_getpass('Hit Enter to go fix it.') faulty_card = Card(front, back, 0, last_viewed) faulty = True return faulty_card, faulty score_string = lines[score_index + 1] if (not score_string.isdigit()) or (not int(score_string) in range(6)): print_error('Error: {} is not a valid score.'.format(score_string)) print_info('Valid scores are 0, 1, 2, 3, 4, 5.') colored_getpass('Hit Enter to go fix it.') faulty_card = Card(front, back, 0, last_viewed) faulty = True return faulty_card, faulty score = int(score_string) edited_card = Card(front, back, score, last_viewed) faulty = False return edited_card, faulty
def new_card(two_way_card, single_line_mode, editor_mode): if editor_mode: return compose_in_editor(two_way_card) else: if single_line_mode: print_instruction('[Ctrl+C: Discard this card and get a menu.]') else: print_instruction( '[Ctrl+D: Finish current side. Ctrl+C: Discard this card and get a menu.]' ) if two_way_card: print_side('Side 1:') else: print_side('Front:') front = read_input(single_line_mode) if front == None: return menu(two_way_card, single_line_mode, editor_mode) if two_way_card: print_side('Side 2:') else: print_side('Back:') back = read_input(single_line_mode) if back == None: return menu(two_way_card, single_line_mode, editor_mode) last_viewed = get_timestamp() card = Card(front, back, 0, last_viewed) return card, two_way_card, single_line_mode, editor_mode