Пример #1
0
 def do_parse(self, arg):
     """Parse and save the output to one of the configured ones"""
     if arg in config['output_formats']:
         utils.parse(arg)
     else:
         Console.print_red('Output format not supported, {}'.format(arg))
         utils.print_outputs()
Пример #2
0
def save(output):
    """ saves the result list to file
    :param output:
    """
    output_file_name = '{}.{}'.format(config['output_file_name'], output)
    if len(pycsverter.result_list) == 0:
        Console.print_red('Parsed result not found, reloading...')
        load()
    Console.print_yellow('Printing output ({}), on file {}'.format(output, output_file_name))
    OutputDumper.dump(pycsverter.result_list, output, output_file_name)
    Console.print_green('Done!')
Пример #3
0
def load(file_path=None):
    """ load the result_list form the csv file
    :param file_path:
    """
    if file_path == '' or file_path is None:
        file_path = config['default_file']

    if os.path.isfile(file_path):
        parsed = import_from_csv(file_path)
        validate_dict(parsed)
    else:
        Console.print_red(
            'File not found in path {}, please specify a valid filePath'.format(file_path))
Пример #4
0
def order_by(field_name):
    """ this function sorts the result list (reverse order if sorted already)
    :param field_name:
    """
    if len(pycsverter.result_list) == 0:
        Console.print_red('Parsed result not found, reloading...')
        load()
    if field_name in pycsverter.result_list[0]:
        Console.print_yellow('Sorting list by {}'.format(field_name))
        pycsverter.result_list.sort(key=lambda x: x[field_name])
        Console.print_green('Done!')
    else:
        Console.print_red('Field {} not in result list:')
        Console.print_blue('Fields available:')
        for k in pycsverter.result_list[0]:
            Console.print_blue(k)
Пример #5
0
def parse(output, file_path=None):
    output_file_name = '{}.{}'.format(config['output_file_name'], output)
    Console.print('converting csv data in {}'.format(output), 'g')
    if file_path is None:
        file_path = config['default_file']

    if os.path.isfile(file_path):
        if len(pycsverter.result_list) == 0:
            parsed = import_from_csv(file_path)
            validate_dict(parsed)
        Console.print_yellow('Printing output ({}), on file {}'.format(output, output_file_name))
        OutputDumper.dump(pycsverter.result_list, output, output_file_name)
        Console.print_green('Done!')
    else:
        Console.print_red(
            'File not found in path {}, please specify a valid filePath'.format(file_path))
Пример #6
0
def print_list(index=None):
    """ prints the result list or just one element
    :param index:
    """
    if len(pycsverter.result_list) == 0:
        Console.print_red('Parsed result not found, reloading...')
        load()
    if index == '':
        index = None
    if index is None:
        print(pycsverter.result_list)
        Console.print_green('Printed all list')
    else:
        try:
            index = int(index)
        except ValueError:
            Console.print_red("{} is not a valid int, nice try!\n index set to 0".format(index))
            index = 0
        if index <= len(pycsverter.result_list):
            print(pycsverter.result_list[index])
            Console.print_green('Printed element {}'.format(index))
Пример #7
0
def results_info():
    """ prints info about the result list """
    if len(pycsverter.result_list) == 0:
        Console.print_red('Parsed result not found...run: load')
    else:
        Console.print_blue('List of {} elements'.format(len(pycsverter.result_list)))