sesamfox

最近在学习交易系统。通过python和tushare数据接口采集基础数据,搭建基础数据环境,踩到了一些坑,特记录下来。

初学python,了解不深,没找到类似mybatis这种ORM接口,因此在批量数据插入时会比较麻烦。

tushare查询,返回的是pandas的DataFrame对象,比较好的办法是用数据库SQL绑定变量的方式将值传到SQL模板。

        dictVal = {
            \'ts_code\'  :row[\'ts_code\'],
            \'symbol\'   :row[\'symbol\'],
            \'name\'     :row[\'name\'],
            \'list_date\':row[\'list_date\'],
        }

python也没有log4j这种日志框架,自带的日志模块也不太好用。于是在python3.6的logging模块之上封装了一层,增加了日志级别的区分

def GetLogger(strLogPath, strLogName, nLevel, logThread=None):
    strLogFile = \'%s.log\' % os.path.join(strLogPath, strLogName)
    formatter = logging.Formatter(
                    \'%(asctime)s %(levelname)-7s:%(message)s\',
                    datefmt = \'%Y-%m-%d %H:%M:%S\')
    RtHandler = RotatingFileHandler(
                    strLogFile, 
                    maxBytes = 2 * 1024 * 1024, 
                    backupCount = 10)
    RtHandler.setLevel(nLevel)
    RtHandler.setFormatter(formatter)

    Console = logging.StreamHandler(sys.stdout)
    Console.setLevel(nLevel)
    Console.setFormatter(formatter)

    if logThread is None:
        logThread = threading.currentThread()
    logThread._logger = logging.getLogger(strLogName)
    logThread._logger.addHandler(RtHandler)
    logThread._logger.addHandler(Console)
    logThread._logger.setLevel(nLevel)

    RtHandler.doRollover()

由于基础数据是要存在MySQL数据库的,平时工作中使用的是Oracle数据库,MySQL与Oracle还是有较大的区别的。于是写了一个数据库维护生成工具,改日分享。

分类:

技术点:

相关文章:

  • 2021-06-22
  • 2021-11-06
  • 2022-01-03
  • 2021-11-01
  • 2021-07-12
  • 2022-01-15
  • 2021-08-04
  • 2021-12-18
猜你喜欢
  • 2021-07-02
  • 2022-01-03
  • 2021-11-05
  • 2021-12-14
  • 2021-10-02
  • 2021-05-31
  • 2022-12-23
相关资源
相似解决方案