Exemplo n.º 1
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!')
Exemplo n.º 2
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)
Exemplo n.º 3
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))
Exemplo n.º 4
0
def validate_dict(parsed):
    Console.print_yellow('Validating data')
    validated = DataValidator.validate(parsed)
    Console.print_green('Validated!')
    pycsverter.result_list = validated
    Console.print_yellow('Result List saved in memory')
Exemplo n.º 5
0
def import_from_csv(file_path):
    Console.print_yellow('Parsing {}...'.format(file_path))
    parsed = CsvImporter.csv_to_dictlist(file_path)
    parsed = convert_star_to_int(parsed)
    Console.print_green('Parsed!')
    return parsed