예제 #1
0
 def process_json2csv(self,
                      src_path,
                      path_to_csv,
                      headers,
                      encoding=ENCODING):
     if self.find_file(src_path):
         json2csv(input_file=src_path,
                  output_file=path_to_csv,
                  header_values=headers,
                  encoding=encoding,
                  row_key=None)
예제 #2
0
 def to_csv(self):
     """Export table from json engine to CSV file"""
     for keys in list(self.script.tables):
         table_name = self.table_name()
         header = self.script.tables[keys].get_insert_columns(join=False, create=True)
         csv_outfile = json2csv(table_name, header_values=header)
         sort_csv(csv_outfile)
예제 #3
0
 def to_csv(self):
     """Export table from json engine to CSV file"""
     for keys in list(self.script.tables):
         table_name = self.table_name()
         header = self.script.tables[keys].get_insert_columns(join=False,
                                                              create=True)
         csv_outfile = json2csv(table_name, header_values=header)
         sort_csv(csv_outfile)
예제 #4
0
 def to_csv(self, sort=True, path=None, select_columns=None):
     """Export table from json engine to CSV file"""
     for table_item in self.script_table_registry[self.script.name]:
         header = table_item[1].get_insert_columns(join=False, create=True)
         outputfile = os.path.normpath(
             os.path.join(path if path else '', os.path.splitext(os.path.basename(table_item[0]))[0] + '.csv'))
         csv_outfile = json2csv(table_item[0], output_file=outputfile, header_values=header)
         sort_csv(csv_outfile)
예제 #5
0
 def to_csv(self, sort=True, path=None, select_columns=None):
     """Export table from json engine to CSV file"""
     for table_item in self.script_table_registry[self.script.name]:
         header = table_item[1].get_insert_columns(join=False, create=True)
         outputfile = os.path.normpath(
             os.path.join(path if path else '', os.path.splitext(os.path.basename(table_item[0]))[0] + '.csv'))
         csv_outfile = json2csv(table_item[0], output_file=outputfile, header_values=header)
         sort_csv(csv_outfile)
예제 #6
0
def test_json2csv(test_name, json_data, header_values, row_key, expected):
    """Test json2csv function.

    Creates a json file and tests the md5 sum calculation.
    """
    json_file = create_file(json_data, 'output.json')
    output_json = json2csv(json_file,
                           "output_json.csv",
                           header_values=header_values,
                           row_key=row_key)
    obs_out = file_2list(output_json)
    os.remove(output_json)
    assert obs_out == expected
예제 #7
0
def test_json2csv():
    """Test json2csv function.

    Creates a json file and tests the md5 sum calculation.
    """
    json_file = create_file([
        """[ {"User": "******", "Country": "US", "Age": "25"} ]"""],
        'output.json')

    output_json = json2csv(json_file, "output_json.csv",
                           header_values=["User", "Country", "Age"])
    obs_out = file_2list(output_json)
    os.remove(output_json)
    assert obs_out == ['User,Country,Age', 'Alex,US,25']
예제 #8
0
def test_json2csv():
    """Test json2csv function.

    Creates a json file and tests the md5 sum calculation.
    """
    json_file = create_file([
        """[ {"User": "******", "Country": "US", "Age": "25"} ]"""],
        'output.json')

    output_json = json2csv(json_file, "output_json.csv",
                           header_values=["User", "Country", "Age"])
    obs_out = file_2list(output_json)
    os.remove(output_json)
    assert obs_out == ['User,Country,Age', 'Alex,US,25']
예제 #9
0
 def to_csv(self, sort=True):
     """Export table from json engine to CSV file"""
     for table_item in self.script_table_registry[self.script.name]:
         header = table_item[1].get_insert_columns(join=False, create=True)
         csv_outfile = json2csv(table_item[0], header_values=header)
         sort_csv(csv_outfile)