コード例 #1
0
def edit(ctx, name):
    """ Edit a Family's Data """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))
    family = directory.get(name)

    family = Prompt.choose_from_list(family, "Which Family? ")

    need_to_save = False
    fam_data = family.to_json()
    fields = sorted(fam_data.keys())
    for name in fields:
        if name in ('id', 'name', 'members'):
            continue

        # TODO: what if notes already exist?
        if name == 'notes':
            new_value = Prompt.notes()
        else:
            old_value = fam_data[name]
            new_value = Prompt.input("%s (%s): " % (name, old_value))

        if new_value:
            need_to_save = True
            setattr(family, name, new_value)

    if need_to_save:
        directory.save()
コード例 #2
0
def edit_member(ctx, name, family_name):
    """ Edit a Family Member """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))

    family, person = __find_member(directory, name, family_name)

    if person:
        need_to_save = False
        person_data = person.to_json()
        fields = sorted(person_data.keys())
        for field in fields:
            if field in ('name', 'photo'):
                continue

            if field == 'phone':
                new_value = Prompt.phone()
                if new_value:
                    person_data['phone'].update(new_value)
                    new_value = person_data['phone']
            elif field == 'relationships':
                new_value = Prompt.relationships()
            else:
                old_value = person_data[field]
                new_value = Prompt.input("%s (%s): " % (field, old_value))

            if new_value:
                need_to_save = True
                setattr(person, field, new_value)

        if need_to_save:
            directory.save()
    else:
        print("Member not found: '%s'" % (name))
コード例 #3
0
def __add_members(family):
    add_members = True
    template = Person().to_json()
    fields = sorted(template.keys())
    while add_members:
        print("----- Add Family Member -----")
        member_data = template.copy()
        for name in fields:
            if name in ('photo'):
                continue

            if name == 'relationships':
                member_data['relationships'] = Prompt.relationships()
            elif name == 'phone':
                member_data['phone'] = Prompt.phone()
            else:
                new_value = Prompt.input("%s: " % (name))
                member_data[name] = new_value if new_value else ""

        member_data['birthday'] = Prompt.input("birthday (YYYY-MM-DD)? ")
        member_data['photo'] = re.sub('\W', '-',
                                      member_data['name'].lower()) + ".jpeg"

        new_member = Person(**member_data)
        family.add(new_member)

        add_members = Prompt.more(msg="Add More Members")
コード例 #4
0
def delete(ctx, name):
    """ Delete a Family from the Directory """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))
    family = directory.get(name)

    family = Prompt.choose_from_list(family, "Which Family? ")

    choice = Prompt.input("Confirm Delete: %s - %s (yes|no)? " %
                          (family.name, family.address))
    if choice == 'yes':
        directory.delete(family)
        directory.save()
    else:
        print("Not Deleting Family: %s - %s" % (family.name, family.address))
コード例 #5
0
ファイル: imprt.py プロジェクト: ccaroon/plebeians
def vcf(ctx, vcf_file):
    """Import VCF Card"""

    config = ctx.obj['config']
    directory = Directory(config.path('data:path', 'directory.json'))

    vcf = VCFParser(photo_dir=config.path('data:path', 'photos'))
    data = vcf.parse(vcf_file)

    print("----- %s - %s -----" % (data['last_name'], data['address']))

    family = directory.get(data['last_name'])
    family = Prompt.choose_from_list(family, "Which Family")
    if family:
        person = family.get(data['name'])
        if person:
            print("%s already exists." % (data['name']))
        else:
            new_person = Person(**data)
            family.add(new_person)
            directory.save()
    else:
        new_family = Family(name=data['last_name'],
                            address=data['address'],
                            city=data['city'],
                            state=data['state'],
                            zip=data['zip'],
                            members=[data])
        directory.add(new_family)
        directory.save()
コード例 #6
0
def view(ctx, name):
    """ View a Family """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))
    family = directory.get(name)

    family = Prompt.choose_from_list(family, "Which Family? ")

    print(repr(family))
コード例 #7
0
def __find_member(directory, name, family_name=None):
    person = None
    family = None
    lookup_name = None

    if family_name:
        lookup_name = family_name
    else:
        name_parts = name.split()
        lookup_name = name_parts.pop()

    family = directory.get(lookup_name)
    family = Prompt.choose_from_list(family, "Which Family? ")

    if family:
        person = family.get(name)

    return (family, person)
コード例 #8
0
def add(ctx, name):
    """ Add a new Family to the Directory """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))

    family_data = Family(name=name).to_json()
    fields = sorted(family_data.keys())
    print("----- Adding the '%s' Family -----" % (family_data['name']))
    for name in fields:
        if name in ('id', 'name', 'members'):
            continue

        new_value = Prompt.input("%s: " % (name))
        family_data[name] = new_value if new_value else ""

    new_family = Family(**family_data)
    print(new_family)
    directory.add(new_family)

    __add_members(new_family)

    directory.save()
コード例 #9
0
ファイル: config.py プロジェクト: MareoRaft/card-game
from lib.prompt import Prompt


# game dynamics
NUM_PENALTY_CARDS = 4

MIN_FACE_VALUE = 2
MAX_FACE_VALUE = 14

MIN_SUIT_VALUE = 1
MAX_SUIT_VALUE = 4

MIN_PLAYERS = 2
MAX_PLAYERS = 4


# color palette
blue = fg(26, 20, 127)
light_blue = fg(45, 120, 255)
gold = fg(248, 194, 15)
red = fg(230, 20, 8)

DEFAULT_TEXT_COLOR = light_blue
ERROR_TEXT_COLOR = red


# make a prompt object for interacting with the user
PROMPT = Prompt(input_prefix='{}>{}>{}>{} '.format(light_blue, gold, red, DEFAULT_TEXT_COLOR),
                output_prefix='\n{}'.format(DEFAULT_TEXT_COLOR),
                warn_prefix=ERROR_TEXT_COLOR)