collector.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:FundSpider 作者: s6530085 项目源码 文件源码
def _load_index_constituent(self, file_path, index_code):
        self._create_constituent_table(index_code)
        excel = xlrd.open_workbook(file_path)
        sheet = excel.sheets()[0]
        current_date = ''
        current_constituent = []
        # ?????????,????,??????????
        row_indent = 1
        if sheet.cell(sheet.nrows-row_indent, 0).value == u'?????????Choice??':
            row_indent = 6
        for row in range(1, sheet.nrows-row_indent):
            # ??,???????????????
            row_date = sheet.cell(row, 1).value
            if isinstance(row_date, float):
                row_date = datetime(*xlrd.xldate_as_tuple(row_date, excel.datemode)).strftime(STAND_DATE_FORMAT)
            #?1????????,??????????????????
            if row == 1:
                current_date = row_date
            # ??????,???????????????
            # ???,????????????,???????????,????????,???????????????????
            # if row_date != current_date or row == sheet.nrows-7:
            if self._in_index_change_range(row_date, current_date) or row == sheet.nrows-7:
                # sql = u'INSERT OR REPLACE INTO {} ({}, {}) VALUES ({}, "{}");'.format(
                #     IndexCollector._constituent_tablename(index_code), IndexConstituent.DATE_KEY, IndexConstituent.CONSTITUENTS_KEY, current_date, ','.join(current_constituent))
                # self.db.execute(sql)
                #???????,????date????????????,??????????
                self.db.execute(u'INSERT OR REPLACE INTO '+ IndexCollector._constituent_tablename(index_code) +' VALUES (?, ?);', (current_date, ','.join(current_constituent)))
                self.db.commit()
                current_date = row_date
            stock_code = sheet.cell(row, 2).value.split('.')[0]
            # ????,?????????b?,?????????????b??????,?????????
            if stock_code.startswith('2'):
                continue
            operation = sheet.cell(row, 4).value
            if operation == u'??':
                current_constituent.append(stock_code)
            else:
                current_constituent.remove(stock_code)

    # ?????????,????????????,????????????
    # ????????????????,??????????????
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号