示例#1
0
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
示例#2
0
文件: edit.py 项目: SebNickel/garrick
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