def test_go_back_remove(self): def go_back(prompt): raise QuestionnaireGoBack(2) q = Questionnaire() q.add('k', prompter=lambda prompt: 'v') q.ask() self.assertEqual(q.answers['k'], 'v') q.add('k2', prompter=lambda prompt: 'v2') q.ask() self.assertEqual(q.answers['k2'], 'v2') q.go_back(1) self.assertEqual(q.answers['k'], 'v') self.assertEqual(q.answers.get('k2'), None) q.ask() self.assertEqual(q.answers['k2'], 'v2') q.add('k3', prompter=go_back) q.ask() self.assertEqual(len(q.answers), 0) q.remove('k2') q.remove('k3') q.run() self.assertEqual(dict(q.answers), {'k': 'v'})
def test_go_back_remove(self): def go_back(prompt): raise QuestionnaireGoBack(2) q = Questionnaire() q.add('k', prompter=lambda prompt: 'v') q.ask() self.assertEqual(q.answers['k'], 'v') q.add('k2', prompter=lambda prompt: 'v2') q.ask() self.assertEqual(q.answers['k2'], 'v2') q.go_back(1) self.assertEqual(q.answers['k'], 'v') self.assertEqual(q.answers.get('k2'), None) q.ask() self.assertEqual(q.answers['k2'], 'v2') q.add('k3', prompter=go_back) q.ask() self.assertEqual(len(q.answers), 0) q.remove('k2') q.remove('k3') q.run() self.assertEqual(dict(q.answers), {'k': 'v'})
def test_format_answers(self): q = Questionnaire() q.add('k', prompter=lambda prompt: 'v') q.run() self.assertEqual(q.format_answers(fmt='obj'), '{"k": "v"}') self.assertEqual(q.format_answers(fmt='array'), '[["k", "v"]]') self.assertEqual(q.format_answers(fmt='plain'), 'k: v')
def test_format_answers(self): q = Questionnaire() q.add('k', prompter=lambda prompt: 'v') q.run() self.assertEqual(q.format_answers(fmt='obj'), '{"k": "v"}') self.assertEqual(q.format_answers(fmt='array'), '[["k", "v"]]') self.assertEqual(q.format_answers(fmt='plain'), 'k: v')
def Questions(): ''' AIM -> Create a good looking questionnaire to generate required arguments to be used with tweet_collection OUTPUT -> String with desired arguments ''' # Initialize Questionnaire q = Questionnaire() # Create Raw Questions q.raw('Search Keyword') q.raw('Number of Tweets', type=int) q.raw('CSV Name') # Run the module q.run() return q.format_answers()
def test_questionnaire(self): q = Questionnaire() q.add('k', prompter=lambda prompt: 'v') q.run() self.assertEqual(q.answers['k'], 'v') q.add('k2', prompter=lambda prompt: 'v2_first').condition(('k', 'v_')) q.add('k2', prompter=lambda prompt: 'v2_second').condition(('k', 'v')) q.ask() self.assertEqual(q.answers['k2'], 'v2_second') self.assertEqual(len(q.answers), 2) q.add('k3', prompter=lambda prompt: randrange(10)).validate( lambda a: None if a == 0 else 'error').transform(lambda a: a - 1) q.ask() self.assertEqual(q.answers['k3'], -1) q.reset() self.assertEqual(dict(q.answers), {})
def test_questionnaire(self): q = Questionnaire() q.add('k', prompter=lambda prompt: 'v') q.run() self.assertEqual(q.answers['k'], 'v') q.add('k2', prompter=lambda prompt: 'v2_first').condition(('k', 'v_')) q.add('k2', prompter=lambda prompt: 'v2_second').condition(('k', 'v')) q.ask() self.assertEqual(q.answers['k2'], 'v2_second') self.assertEqual(len(q.answers), 2) q.add('k3', prompter=lambda prompt: randrange(10)).validate( lambda a: None if a == 0 else 'error' ).transform(lambda a: a-1) q.ask() self.assertEqual(q.answers['k3'], -1) q.reset() self.assertEqual(dict(q.answers), {})
def two(options): if len(options) < 2: return 'You must choose at least 2 options' def join(options): return ', '.join(options) q.many('options', 'Option 1', 'Option 2', 'Option 3', prompt='Choose some options').validate(two).transform(join) q.many('more', 'Option 4', 'Option 5', 'Option 6', prompt='Choose some more').validate(two).transform(join) q.run() print(q.answers) q.many('yet_more', 'Option 7', 'Option 8', prompt='And more...', default=[0, 1]) q.many('done', 'Option 9', 'Option 10', prompt='Last ones', default=1) q.run() print(q.answers)
from questionnaire import Questionnaire import requests q = Questionnaire(show_answers=False, can_go_back=False) q.raw('user', prompt='Username:'******'pass', prompt='Password:'******'https://api.github.com/user/repos', auth=(q.answers.get('user'), q.answers.get('pass'))) if not(r.ok): import sys print('username/password incorrect') sys.exit() repos = [repo.get('url') for repo in r.json()] q.one('repo', *repos, prompt='Choose a repo') q.run() print(q.answers.get('repo'))
options=['service', 'webserver', 'database', 'webapp', 'api', 'message',]).\ add_condition(keys=['kind'], vals=['service']) # TAGS q.add_question('tags', prompter="multiple", options=['aws_cli', 'bower', 'clone_repo', 'collectstatic', 'createsuperuser', 'cron', 'django', 'env_vars', 'fixtures', 'iptables', 'logrotate', 'migrate', 'nginx', 'node', 'postgresql', 'redis', 'staticfiles', 'upstart', 'vagrant', 'virtualenv']).\ add_condition(keys=['kind'], vals=['deploy']) # BRANCH q.add_question('branch', prompter="raw").add_condition(keys=['kind'], vals=['deploy']) # ACTION q.add_question('action', options=['started', 'stopped', 'restarted', 'reloaded']).\ add_condition(keys=['kind'], vals=['service']) # SERVICES q.add_question('services', prompter="multiple", options=SERVICES_DEV).\ add_condition(keys=['kind', 'env'], vals=['service', 'development']) q.add_question('services', prompter="multiple", options=SERVICES_STG).\ add_condition(keys=['kind', 'env'], vals=['service', 'staging']) q.add_question('services', prompter="multiple", options=SERVICES_PRD).\ add_condition(keys=['kind', 'env'], vals=['service', 'production']) answers = q.run() command = generate(**answers) print("\nTHE FOLLOWING COMMAND HAS BEEN COPIED TO YOUR CLIPBOARD:\n\n{}\n". format(command)) pyperclip.copy(command)
#!/usr/bin/env python from questionnaire import Questionnaire from languages import every_language, language_name_list from google.cloud import * from generator import generate q = Questionnaire() q.one("What is your language", 'Afrikaans', 'Albanian', 'Amharic', 'Arabic', 'Armenian', 'Azerbaijani', 'Basque', 'Belarusian', 'Bengali', 'Bosnian', 'Bulgarian', 'Catalan', 'Cebuano', 'Chichewa', 'Chinese (Simplified)', 'Chinese (Traditional)', 'Corsican', 'Croatian', 'Czech', 'Danish', 'Dutch', 'English', 'Esperanto', 'Estonian', 'Filipino', 'Finnish', 'French', 'Frisian', 'Galician', 'Georgian', 'German', 'Greek', 'Gujarati', 'Haitian Creole', 'Hausa', 'Hawaiian', 'Hebrew', 'Hindi', 'Hmong', 'Hungarian', 'Icelandic', 'Igbo', 'Indonesian', 'Irish', 'Italian', 'Japanese', 'Javanese', 'Kannada', 'Kazakh', 'Khmer', 'Korean', 'Kurdish (Kurmanji)', 'Kyrgyz', 'Lao', 'Latin', 'Latvian', 'Lithuanian', 'Luxembourgish', 'Macedonian', 'Malagasy', 'Malay', 'Malayalam', 'Maltese', 'Maori', 'Marathi', 'Mongolian', 'Myanmar (Burmese)', 'Nepali', 'Norwegian', 'Pashto', 'Persian', 'Polish', 'Portuguese', 'Punjabi', 'Romanian', 'Russian', 'Samoan', 'Scots Gaelic', 'Serbian', 'Sesotho', 'Shona', 'Sindhi', 'Sinhala', 'Slovak', 'Slovenian', 'Somali', 'Spanish', 'Sundanese', 'Swahili', 'Swedish', 'Tajik', 'Tamil', 'Telugu', 'Thai', 'Turkish', 'Ukrainian', 'Urdu', 'Uzbek', 'Vietnamese', 'Welsh', 'Xhosa', 'Yiddish', 'Yoruba', 'Zulu') q.run() a = q.format_answers(fmt='plain'); a = a.split(" ") #language of choice abbreviated_language = language_name_list[every_language.index(a[-1])][0] # Instantiates a client translate_client = translate.Client() # Translates Quetionire into desired language # translation = translate_client.translate(text,target_language=abbreviated_language) q = Questionnaire() q.raw(translate_client.translate('first_name',target_language=abbreviated_language)['translatedText'], prompt= translate_client.translate('What is your First Name?',target_language=abbreviated_language)['translatedText']) q.raw(translate_client.translate('last_name',target_language=abbreviated_language)['translatedText'],prompt=translate_client.translate('What is your Last Name?',target_language=abbreviated_language)['translatedText']) q.raw(translate_client.translate("email",target_language=abbreviated_language)['translatedText'],prompt=translate_client.translate('What is your email? ',target_language=abbreviated_language)['translatedText']) q.raw(translate_client.translate("phone_number",target_language=abbreviated_language)['translatedText'],prompt=translate_client.translate('What is your phone number?',target_language=abbreviated_language)['translatedText']) q.raw(translate_client.translate("address_line_1",target_language=abbreviated_language)['translatedText'],prompt=translate_client.translate('What is your street address?',target_language=abbreviated_language)['translatedText']) q.raw(translate_client.translate("city",target_language=abbreviated_language)['translatedText'],prompt=translate_client.translate('What city?',target_language=abbreviated_language)['translatedText']) q.raw(translate_client.translate("country",target_language=abbreviated_language)['translatedText'],prompt=translate_client.translate('What country?',target_language=abbreviated_language)['translatedText'])
q.add_question('playbooks', prompter="multiple", options=['service', 'webserver', 'database', 'webapp', 'api', 'message',]).\ add_condition(keys=['kind'], vals=['service']) # TAGS q.add_question('tags', prompter="multiple", options=['aws_cli', 'bower', 'clone_repo', 'collectstatic', 'createsuperuser', 'cron', 'django', 'env_vars', 'fixtures', 'iptables', 'logrotate', 'migrate', 'nginx', 'node', 'postgresql', 'redis', 'staticfiles', 'upstart', 'vagrant', 'virtualenv']).\ add_condition(keys=['kind'], vals=['deploy']) # BRANCH q.add_question('branch', prompter="raw").add_condition(keys=['kind'], vals=['deploy']) # ACTION q.add_question('action', options=['started', 'stopped', 'restarted', 'reloaded']).\ add_condition(keys=['kind'], vals=['service']) # SERVICES q.add_question('services', prompter="multiple", options=SERVICES_DEV).\ add_condition(keys=['kind', 'env'], vals=['service', 'development']) q.add_question('services', prompter="multiple", options=SERVICES_STG).\ add_condition(keys=['kind', 'env'], vals=['service', 'staging']) q.add_question('services', prompter="multiple", options=SERVICES_PRD).\ add_condition(keys=['kind', 'env'], vals=['service', 'production']) answers = q.run() command = generate(**answers) print("\nTHE FOLLOWING COMMAND HAS BEEN COPIED TO YOUR CLIPBOARD:\n\n{}\n".format(command)) pyperclip.copy(command)