def main(): """Main. """ if cutie.prompt_yes_or_no('Are you brave enough to continue?'): # List of names to select from, including some captions names = [ 'Kings:', 'Arthur, King of the Britons', 'Knights of the Round Table:', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Swedish captions:', 'Møøse' ] # Names which are captions and thus not selectable captions = [0, 2, 7] # Get the name name = names[cutie.select(names, caption_indices=captions, selected_index=8)] print(f'Welcome, {name}') # Get an integer greater or equal to 0 age = cutie.get_number('What is your age?', min_value=0, allow_float=False) nemeses_options = [ 'The French', 'The Police', 'The Knights Who Say Ni', 'Women', 'The Black Knight', 'The Bridge Keeper', 'Especially terrifying:', 'The Rabbit of Caerbannog', ] print('Choose your nemeses') # Choose multiple options from a list nemeses_indices = cutie.select_multiple(nemeses_options, caption_indices=[6]) nemeses = [ nemesis for nemesis_index, nemesis in enumerate(nemeses_options) if nemesis_index in nemeses_indices ] # Get input without showing it being typed quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.') if nemeses: if len(nemeses) == 1: print(f'His nemesis is {nemeses[0]}.') else: print(f'His nemeses are {" and ".join(nemeses)}.') else: print('He has no nemesis.')
def main(): """Main. """ if cutie.prompt_yes_or_no('Are you brave enough to continue?'): names = [ 'Arthur, King of the Britons', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Møøse' ] name = names[cutie.select(names, selected_index=5)] print(f'Welcome, {name}') age = cutie.get_number('What is your age?', min_value=0, allow_float=False) quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.')
def login(): global token username = input('Enter your username: '******'Enter your password: '******'http://localhost:5000/api/user/login', json={ 'username': username, 'password': pwd }) # Check 401 Unauthorized if r.status_code == 401: print('Incorrect username or password.') return token = r.json()['token'] print('Login successful.')
def create_account(): global token name = input('Enter your name: ') username = input('Enter a username: '******'Select a password: '******'http://localhost:5000/api/user/signup', json={ 'name': name, 'username': username, 'password': pwd }) # Check 409 Conflict if r.status_code == 409: print('Username already exists.') return token = r.json()['token'] print('Account successfully created. You are now logged in.')
import cutie import pprint if cutie.prompt_yes_or_no('Are you brave enough to continue?'): # List of names to select from, including some captions names = [ 'Kings:', 'Arthur, King of the Britons', 'Knights of the Round Table:', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Swedish captions:', 'Møøse' ] # Names which are captions and thus not selectable captions = [0, 2, 7] # Get the name # name = names[cutie.select(names, caption_indices=captions, selected_index=8)] # print(f'Welcome, {name}') # get multiple selected = cutie.select_multiple(names, caption_indices=captions) pprint.pprint(selected) # Get an integer greater or equal to 0 age = cutie.get_number('What is your age?', min_value=0, allow_float=False) # Get input without showing it being typed quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.')
def test_secure_input(self): with mock.patch("cutie.getpass.getpass", return_value="foo") as mock_getpass: self.assertEqual(cutie.secure_input("foo"), "foo") mock_getpass.assert_called_once_with("foo ")