Esempio n. 1
0
 def to_csv(self):
     """Export table from xml engine to CSV file."""
     for keys in list(self.script.tables):
         table_name = self.opts['table_name'].format(db=self.db_name, table=keys)
         header = self.script.tables[keys].get_insert_columns(join=False, create=True)
         csv_outfile = xml2csv(table_name, header_values=header)
         sort_csv(csv_outfile)
Esempio n. 2
0
 def to_csv(self):
     """Export table from json engine to CSV file"""
     for keys in list(self.script.tables):
         table_name = self.opts['table_name'].format(db=self.db_name,
                                                     table=keys)
         header = self.script.tables[keys].get_insert_columns(join=False,
                                                              create=True)
         csv_outfile = json2csv(table_name, header_values=header)
         sort_csv(csv_outfile)
Esempio n. 3
0
def test_sort_csv():
    """Test md5 sum calculation"""
    data_file = create_file("User,Country,Age\nBen,US,24\nAlex,US,25\nAlex,PT,25")
    out_file = sort_csv(data_file)
    obs_out = file_2string(out_file)
    os.remove(out_file)
    assert obs_out == "User,Country,Age\nAlex,PT,25\nAlex,US,25\nBen,US,24\n"
Esempio n. 4
0
def test_sort_csv():
    """Test md5 sum calculation"""
    data_file = create_file(
        "User,Country,Age\nBen,US,24\nAlex,US,25\nAlex,PT,25")
    out_file = sort_csv(data_file)
    obs_out = file_2string(out_file)
    assert obs_out == "User,Country,Age\nAlex,PT,25\nAlex,US,25\nBen,US,24\n"
Esempio n. 5
0
def test_sort_csv():
    """Test md5 sum calculation."""
    data_file = create_file(
        ['User,Country,Age', 'Ben,US,24', 'Alex,US,25', 'Alex,PT,25'])
    out_file = sort_csv(data_file)
    obs_out = file_2list(out_file)
    os.remove(out_file)
    assert obs_out == [
        'User,Country,Age', 'Alex,PT,25', 'Alex,US,25', 'Ben,US,24'
    ]
Esempio n. 6
0
 def to_csv(self):
     # Due to Cyclic imports we can not move this import to the top
     from retriever.lib.tools import sort_csv
     for _ in list(self.script.urls.keys()):
         table_name = self.table_name()
         csv_file_output = os.path.normpath(table_name + '.csv')
         csv_file = open_fw(csv_file_output)
         csv_writer = open_csvw(csv_file)
         self.get_cursor()
         self.set_engine_encoding()
         self.cursor.execute("SELECT * FROM  {};".format(table_name))
         row = self.cursor.fetchone()
         colnames = [u'{}'.format(tuple_i[0]) for tuple_i in self.cursor.description]
         csv_writer.writerow(colnames)
         while row is not None:
             csv_writer.writerow(row)
             row = self.cursor.fetchone()
         csv_file.close()
         sort_csv(csv_file_output)
     self.disconnect()
Esempio n. 7
0
 def to_csv(self):
     # due to Cyclic imports we can not move this import to the top
     from retriever.lib.tools import sort_csv
     for item in list(self.script.urls.keys()):
         table_name = self.table_name()
         csv_file_output = os.path.normpath(table_name + '.csv')
         csv_file = open_fw(csv_file_output)
         csv_writer = open_csvw(csv_file)
         self.get_cursor()
         self.set_engine_encoding()
         self.cursor.execute("SELECT * FROM  {};".format(table_name))
         row = self.cursor.fetchone()
         colnames = [u'{}'.format(tuple_i[0]) for tuple_i in self.cursor.description]
         csv_writer.writerow(colnames)
         while row is not None:
             csv_writer.writerow(row)
             row = self.cursor.fetchone()
         csv_file.close()
         sort_csv(csv_file_output)
     self.disconnect()
Esempio n. 8
0
def test_sort_csv():
    """Test md5 sum calculation."""
    data_file = create_file(['User,Country,Age',
                             'Ben,US,24',
                             'Alex,US,25',
                             'Alex,PT,25'])
    out_file = sort_csv(data_file)
    obs_out = file_2list(out_file)
    os.remove(out_file)
    assert obs_out == [
        'User,Country,Age',
        'Alex,PT,25',
        'Alex,US,25',
        'Ben,US,24']
Esempio n. 9
0
 def to_csv(self):
     # due to Cyclic imports we can not move this import to the top
     from retriever.lib.tools import sort_csv
     csvfile_output = (self.table_name() + '.csv')
     csv_out = open(csvfile_output, "wb")
     csv_writer = csv.writer(csv_out, dialect='excel')
     self.get_cursor()
     self.cursor.execute("SELECT * FROM " + self.table_name() + ";")
     row = self.cursor.fetchone()
     colnames = [tuple_i[0] for tuple_i in self.cursor.description]
     csv_writer.writerow(colnames)
     while row is not None:
         csv_writer.writerow(row)
         row = self.cursor.fetchone()
     csv_out.close()
     self.disconnect()
     return sort_csv(csvfile_output)
Esempio n. 10
0
 def to_csv(self):
     # due to Cyclic imports we can not move this import to the top
     from retriever.lib.tools import sort_csv
     csvfile_output = (self.table_name() + '.csv')
     csv_out = open(csvfile_output, "w")
     csv_writer = csv.writer(csv_out, dialect='excel', lineterminator='\n')
     self.get_cursor()
     self.cursor.execute("SELECT * FROM " + self.table_name() + ";")
     row = self.cursor.fetchone()
     colnames = [tuple_i[0] for tuple_i in self.cursor.description]
     csv_writer.writerow(colnames)
     while row is not None:
         csv_writer.writerow(row)
         row = self.cursor.fetchone()
     csv_out.close()
     self.disconnect()
     return sort_csv(csvfile_output)
Esempio n. 11
0
 def to_csv(self):
     """Export sorted version of CSV file"""
     return sort_csv(self.table_name())
Esempio n. 12
0
 def to_csv(self):
     """Export sorted version of CSV file"""
     for keys in self.script.tables:
         table_name = self.opts['table_name'].format(db=self.db_name, table=keys)
         sort_csv(table_name)
Esempio n. 13
0
 def to_csv(self):
     """Export table from xml engine to CSV file"""
     keys = [columnname[0] for columnname in self.table.columns]
     csv_outfile = xml2csv(self.table_name(), header_values=keys)
     return sort_csv(csv_outfile)
Esempio n. 14
0
 def to_csv(self):
     """Export sorted version of CSV file"""
     return sort_csv(self.table_name())
Esempio n. 15
0
 def to_csv(self):
     """Export table from json engine to CSV file"""
     keys = self.table.get_insert_columns(join=False, create=True)
     csv_outfile = json2csv(self.table_name(), header_values=keys)
     return sort_csv(csv_outfile)