Exemplo n.º 1
0
class TestBot(TestCase):
    def setUp(self):
        self.__dude = ChatBot()
        self.__SALUTATION_RESPONSES = ["hi", "hello", "how's tricks?"]
        app = Flask(__name__, instance_relative_config=True)
        PWD = os.path.abspath(os.curdir)
        i_c = IntegrationConfig
        i_c.SQLALCHEMY_DATABASE_URI ='sqlite:///{}/reporting.db'.format(PWD)
        app.config.from_object(i_c)

        app.config['DATABASE'] = PWD
        app.config['TESTING'] = True
        self.app = app.test_client()

        app_settings = {
            'file': ABS_FILE_PATH['COMPLETE_CSV_SM'],
            'currency': 'USD',
            'database_path': PWD,
        }
        serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
        with app.app_context():
            db.init_app(app)
            db.create_all()
            load_db(file=ABS_FILE_PATH['COMPLETE_CSV_SM'],location=PWD)

    def test_chat_bot(self):
        greeting1 = self.__dude.chat_machine("hello")[0]
        self.assertIn(*greeting1, self.__SALUTATION_RESPONSES)
        self.assertEqual('<a href="/sku_detail/36">Here you go!</a>', *self.__dude.chat_machine("show KR202-244")[0])
Exemplo n.º 2
0
def step_impl(context):
    """
    Args:
        context (behave.runner.Context):
    """

    bot = ChatBot()
    context.response = bot.chat_machine(message='Hello')
    assert context.response
Exemplo n.º 3
0
def step_impl(context):
    """
    Args:
        context (behave.runner.Context):
    """


    bot = ChatBot()
    context.response = bot.chat_machine(message='Hello')
    assert context.response
Exemplo n.º 4
0
def chat(message: str = None):
    """ Rest api for chat bot

    Args:
        message: User query to chat bot.

    Returns:
        json:   Response from chat bot.

    """
    dash = ChatBot()
    response = dash.chat_machine(message=message)

    return flask.jsonify(json_list=response)
Exemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(
        description='Supplychainpy commandline interface a')

    parser.add_argument(dest='filenames', metavar='filename', nargs='?')

    parser.add_argument(
        '-l',
        '--launch',
        dest='launch',
        action='store_true',
        help='Launches supplychainpy reporting gui for setting \
                        port and launching the default browser.')

    parser.add_argument(
        '-lx',
        '--launch-console',
        dest='launch_console',
        action='store_true',
        help='Launches supplychainpy reporting in the default browser, \
                        without gui interface. Uses default port (5000) unless another port \
                        is specified. ')

    parser.add_argument(
        '-a',
        '--analyse',
        dest='analyse_file',
        action='store_true',
        help='Processes the file supplied as the first argument \
                        and performs analysis')

    parser.add_argument('-o',
                        dest='outfile',
                        action='store',
                        help='output file')

    parser.add_argument('-v',
                        '--verbose',
                        dest='verbose',
                        action='store_true',
                        help='verbose mode')

    parser.add_argument('-db',
                        dest='database',
                        action='store',
                        help='database engine uri e.g. ')

    parser.add_argument(
        '-cur',
        dest='currency',
        action='store',
        help='Sets the currency for the analysis. The currency should \
                        match the currency of the raw data. IMPORTANT: Currency \
                        conversion does not occur by setting this flag. The default \
                        currency is US Dollars (USD). ',
        default='USD')

    parser.add_argument('--host',
                        dest='host',
                        action='store',
                        help='Sets the host for the server \
                        (defaults 127.0.0.1) ',
                        default='127.0.0.1')

    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        help='Runs in debug mode (default : debug.INFO)')

    parser.add_argument('-loc',
                        dest='location',
                        action='store',
                        help='database path e.g. ')

    parser.add_argument('-u', dest='user', action='store', help='user name ')

    parser.add_argument('-p',
                        '--port',
                        dest='port',
                        action='store',
                        help='port to use for local server e.g. 8080 \
                        (default: 5000)',
                        default='5000')

    parser.add_argument('-c',
                        dest='chat',
                        action='store_true',
                        help='chat to dash from the command line')

    args = parser.parse_args()

    if args.verbose:
        print('filenames = {}'.format(args.filenames))
        print('launch reports = {}'.format(args.launch))
        print('process file = {}'.format(args.analyse_file))
        print('database location = {}'.format(args.location))

    if args.debug:
        logging.basicConfig(level=logging.INFO,
                            format='%(asctime)s - %(levelname)s - %(message)s')

    if args.launch and args.analyse_file is None and args.filenames is not None and args.location:
        # -l -loc
        print(1)

        if args.currency is not None:
            currency = args.currency
        else:
            currency = 'USD'
        app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG)
        app_settings['database_path'] = args.location
        app_settings['file'] = args.filenames
        app_settings['currency'] = currency

        serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
        #d = _Orchestrate()
        #d.copy_file()
        #db_present = d.check_for_db()
        #if db_present:
        #    create_management_db()
        launch_load_report(args.filenames, args.location)

    elif args.launch and args.analyse_file and args.filenames is not None and args.location is not None:
        # -a -loc -l
        print(2)

        if args.currency is not None:
            currency = args.currency
        else:
            currency = 'USD'
        app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG)
        app_settings['database_path'] = args.location
        app_settings['file'] = args.filenames
        app_settings['currency'] = currency

        serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
        #d = _Orchestrate()
        #d.copy_file()
        #db_present = d.check_for_db()
        #if db_present:
        #    create_management_db()
        launch_load_report(args.filenames, args.location)

    elif args.launch and args.location is not None and args.host:
        # -l -loc --host
        print(3)

        app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG)

        app_settings['database_path'] = args.location
        app_settings['port'] = args.port

        serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)

        launch_report(location=args.location, host=args.host, port=args.port)

    elif args.launch and args.analyse_file and args.filenames and args.location:
        # -a -l -loc
        print(4)

        if args.currency is not None:
            currency = args.currency
        else:
            currency = 'USD'

        app_settings = deserialise_config(ABS_FILE_PATH_APPLICATION_CONFIG)
        app_settings['database_path'] = args.location
        app_settings['file'] = args.filenames
        app_settings['currency'] = currency

        serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
        #d = _Orchestrate()
        #d.copy_file()
        #db_present = d.check_for_db()
        #if db_present:
        #    create_management_db()
        launch_load_report(args.filenames, args.location)
        launch_report(location=args.location, host=args.host, port=args.port)

    elif args.analyse_file and args.location is not None and args.filenames is not None and args.launch_console is None:
        # -a
        load_db(file=args.filenames, location=args.location)

    elif args.analyse_file and args.location and args.filenames and args.launch_console and args.port:
        # -a -loc --lx -p
        try:
            print(5)
            app_settings = {
                'database_path': args.location,
                'file': args.filenames,
                'currency': args.currency
            }
            serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
            #d = _Orchestrate()
            #d.copy_file()
            #db_present = d.check_for_db()
            #if db_present:
            #    create_management_db()
            load_db(file=args.filenames, location=args.location)
            launch_report_server(location=args.location,
                                 port=args.port,
                                 host=args.host)
        except OSError as e:
            print(e)

    elif args.location and args.launch_console and args.port and args.host:
        # -loc -lx -p --host
        try:
            print(6)

            app_settings = {
                'database_path': args.location,
                'host': args.host,
                'currency': args.currency
            }
            serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
            launch_report_server(location=args.location,
                                 port=args.port,
                                 host=args.host)
        except OSError as e:
            print(e)

    elif args.analyse_file and args.location is not None and args.filenames is not None and args.launch_console is None and args.host:
        # -a -loc -lx --host
        print(7)

        app_settings = {
            'database_path': args.location,
            'host': args.host,
            'currency': args.currency
        }
        serialise_config(app_settings, ABS_FILE_PATH_APPLICATION_CONFIG)
        launch_report_server(location=args.location,
                             port=args.port,
                             host=args.host)

    elif args.chat:
        msg = input("Enter message for Dash: ")
        while msg != 'q':
            dash = ChatBot()
            response = dash.chat_machine(message=msg)
            for i in response:
                print('Dash> ', i)
            msg = input("> ")