コード例 #1
0
def new_gender():
    g = input('Enter your gender (enter \'m\' for male or \'f\' for female): ')
    while ctf.are_same_str(g, "m") == 0 and ctf.are_same_str(g, "f") == 0:
        g = input(
            'Incorrect input. Enter either \'m\' for male or \'f\' for female): '
        )
    return g
コード例 #2
0
def delete_food():
    name = validate_food_name_delete()
    inp = input('\nAre you sure you want to delete food item (y/n)?: ')
    while ctf.are_same_str(inp, "y") == 0 and ctf.are_same_str(inp, "n") == 0:
        print('Invalid input. Type in either \'y\' or \'n\'.')
        inp = input('\nAre you sure you want to delete food item (y/n)?: ')
    if inp == "y":
        url = ROOT_URL + 'delete_food?f=' + name
        response = requests.delete(url)
        return True
    else:
        return False
コード例 #3
0
def confirm_user_update(attr, val):
    print('\nUser update summary:')
    print('Attribute to update:', attr)
    print('New value:', val)
    inp = input('\nConfirm change (y/n)?: ')
    while ctf.are_same_str(inp, "y") == 0 and ctf.are_same_str(inp, "n") == 0:
        print('Invalid input. Type in either \'y\' or \'n\'.')
        inp = input('Confirm user (y/n)?: ')
    if inp == "y":
        return True
    else:
        return False
コード例 #4
0
def confirm_new_food(name, cal, size):
    print('\nNew food summary:')
    print('Name:', name)
    print('Total calories:', cal)
    print('Serving size:', size, 'g')
    inp = input('\nConfirm food (y/n)?: ')
    while ctf.are_same_str(inp, "y") == 0 and ctf.are_same_str(inp, "n") == 0:
        print('Invalid input. Type in either \'y\' or \'n\'.')
        inp = input('Confirm user (y/n)?: ')
    if inp == "y":
        return True
    else:
        return False
コード例 #5
0
def confirm_calorie_update(user, food, servings, cal_amt):
    print('Food entered:', food['name'])
    print('Servings entered:', servings)
    print('Current calories consumed today:',
          '{:.2f}'.format(user['cal_today']))
    print('New calories consumed:', '{:.2f}'.format(cal_amt))
    print('New calorie total:', '{:.2f}'.format(user['cal_today'] + cal_amt))
    inp = input('\nConfirm calorie update (y/n)?: ')
    while ctf.are_same_str(inp, "y") == 0 and ctf.are_same_str(inp, "n") == 0:
        print('Invalid input. Type in either \'y\' or \'n\'.')
        inp = input('Confirm user (y/n)?: ')
    if inp == "y":
        return True
    else:
        return False
コード例 #6
0
def confirm_new_user(u, pw, first_name, last_name, age, gender, h, act_lvl,
                     goal):
    print('\nNew user summary:')
    print('Username:'******'Password:'******'First name:', first_name)
    print('Last name:', last_name)
    print('Age:', age)
    print('Gender:', ctf.get_gender_str(gender))
    print('Height:', h, 'cm')
    print('Activity level:', ctf.explain_activity_level(act_lvl))
    print('Weight goal:', ctf.explain_goal(goal))
    inp = input('\nConfirm user (y/n)?: ')
    while ctf.are_same_str(inp, "y") == 0 and ctf.are_same_str(inp, "n") == 0:
        print('Invalid input. Type in either \'y\' or \'n\'.')
        inp = input('Confirm user (y/n)?: ')
    if inp == "y":
        return True
    else:
        return False
コード例 #7
0
def new_username():
    u = input('Enter a username: '******'check_user?u='
    url = base_url + u
    response = requests.get(url)
    resp_code = response.text
    while ctf.are_same_str(resp_code, "1") == 1:
        u = input('Username already taken. Please enter another username: ')
        url = base_url + u
        response = requests.get(url)
        resp_code = response.text
    return u
コード例 #8
0
def new_food_name():
    name = input('Enter the name of the food item: ')
    base_url = ROOT_URL + 'check_food?f='
    url = base_url + name
    response = requests.get(url)
    resp_code = response.text
    while ctf.are_same_str(resp_code, "1") == 1:
        name = input(
            'Food already exists in server. Please enter another food item: ')
        url = base_url + name
        response = requests.get(url)
        resp_code = response.text
    return name
コード例 #9
0
def validate_food_name_delete():
    name = input('Enter name of food to delete: ')
    base_url = ROOT_URL + 'check_food?f='
    url = base_url + name
    response = requests.get(url)
    resp_code = response.text
    while ctf.are_same_str(resp_code, "0") == 1:
        name = input(
            'Food item cannot be found. Please enter the name of the food properly: '
        )
        url = base_url + name
        response = requests.get(url)
        resp_code = response.text
    return name
コード例 #10
0
def update_food():
    name = validate_food_name()

    food_attr_sel_str = make_sels_str(food_attr)

    sel = user_interaction(food_attr_sel_str, len(food_attr))
    while ctf.are_same_str(sel, "") == 1:
        print(INVALID_INPUT_MSG)
        sel = user_interaction(food_attr_sel_str, len(food_attr))
    attr_str = food_attr[int(sel)]

    val = ''
    if ctf.are_same_str(attr_str, 'calories') == 1:
        val = new_food_cal()
    else:
        val = new_serving()

    if confirm_food_update(name, attr_str, val):
        url = ROOT_URL + 'update/food/' + attr_str + '?name=' + name + '&val=' + val
        response = requests.post(url)
        return True
    else:
        return False
コード例 #11
0
def startup_test_conn():
    response = ""
    url = ROOT_URL + 'test'
    try:
        response = requests.get(url, timeout=10)
    except requests.exceptions.ConnectionError:
        print(
            'Cannot connect to meal_server.js. Turn on node.js server first before running program.'
        )
        sys.exit(0)
    if ctf.are_same_str(response.text, "secret message") == 0:
        print(
            'Established connection but not test strings do not match. Check meal_server.js for more.'
        )
        sys.exit(0)
コード例 #12
0
def update_user(user):
    user_attr_sel_str = make_sels_str(user_attr)

    sel = user_interaction(user_attr_sel_str, len(user_attr))
    while ctf.are_same_str(sel, "") == 1:
        print(INVALID_INPUT_MSG)
        sel = user_interaction(user_attr_sel_str, len(user_attr))
    attr_str = user_attr[int(sel)]

    val = ''
    if ctf.are_same_str(attr_str, 'password') == 1:
        val = input('Enter a password: '******'first_name') == 1:
        val = input('Enter your first name: ')
    elif ctf.are_same_str(attr_str, 'last_name') == 1:
        val = input('Enter your last name: ')
    elif ctf.are_same_str(attr_str, 'age') == 1:
        val = new_age()
    elif ctf.are_same_str(attr_str, 'gender') == 1:
        val = new_gender()
    elif ctf.are_same_str(attr_str, 'height') == 1:
        val = new_height()
    elif ctf.are_same_str(attr_str, 'activity_level') == 1:
        val = new_act_lvl()
    else:
        val = new_goal()

    if confirm_user_update(attr_str, val):
        url = ROOT_URL + 'update/user/' + attr_str + '?username='******'username'] + '&val=' + val
        response = requests.post(url)
        print('\nUpdate successful')
        return response.json()
    else:
        print('\nUser update cancelled.')
        return user