コード例 #1
0
ファイル: broker_stock_csv.py プロジェクト: jiafeiyan/xops
 def __produce_csv(self, csv_name, columns, csv_data):
     self.logger.info("%s%s%s" % ("开始生成 ", csv_name, ".csv"))
     _path = self.csv_path + os.path.sep + csv_name + '.csv'
     # 如果不存在目录则先创建
     if not os.path.exists(str(self.csv_path)):
         os.makedirs(str(self.csv_path))
     with open(_path, 'wb') as csvfile:
         if "quoting" in columns and columns['quoting']:
             writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
         else:
             writer = csv.writer(csvfile)
         writer.writerow(csv_tool.covert_to_gbk(columns['columns']))
         writer.writerows(csv_tool.covert_to_gbk(csv_data))
     self.logger.info("%s%s%s" % ("生成 ", csv_name, ".csv 文件完成"))
コード例 #2
0
 def __handle_csv(self, table_name, data_set, quoting=None):
     self.logger.info("%s%s%s" % ("开始追加 [", table_name, ".csv] 数据"))
     _path = "%s%s%s%s" % (str(self.csv_path), os.path.sep, table_name, '.csv')
     if not os.path.exists(_path):
         self.logger.error("%s%s%s" % ("文件", table_name, ".csv不存在!"))
     else:
         with open(_path, "ab+") as target:
             if quoting:
                 writer = csv.writer(target, quoting=csv.QUOTE_ALL)
             else:
                 writer = csv.writer(target)
             writer.writerows(csv_tool.covert_to_gbk(data_set))
         self.logger.info("%s%s%s" % ("追加 [", table_name, "] 数据完成"))
コード例 #3
0
ファイル: gen_investor.py プロジェクト: jiafeiyan/xops
def produce_csv(columns, csv_data, _path):
    with open(_path, 'wb') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(csv_tool.covert_to_gbk(columns))
        writer.writerows(csv_tool.covert_to_gbk(csv_data))