priceapi.py 文件源码

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

项目:priceAPI 作者: yorikvanhavre 项目源码 文件源码
def build(self):
        import xlrd
        tf = os.path.dirname(os.path.abspath(__file__))+os.sep+"sources"+os.sep+"pmsp.xls"
        if not tf:
            tf = self.download()
        if not tf:
            return
        f = xlrd.open_workbook(tf)
        self.descriptions = []
        self.values = []
        self.units = []
        self.codes = []
        sh = f.sheets()[0]
        for i in range(1,sh.nrows):
            r = sh.row(i)
            if (r[0].ctype == xlrd.XL_CELL_NUMBER) and (r[1].ctype == xlrd.XL_CELL_TEXT) and (r[7].ctype == xlrd.XL_CELL_TEXT) and (r[9].ctype == xlrd.XL_CELL_NUMBER):
                c = str(int(r[0].value))
                cs = c[0:2]+"."+c[2:4]+"."
                if len(c[4:]) == 1:
                    cs += "0"+c[4:]
                else:
                    cs += c[4:]
                self.codes.append(cs)
                self.descriptions.append(r[1].value)
                self.units.append(r[7].value)
                self.values.append(r[9].value)
        #f.close()
        print "parsed data: ",len(self.codes),"/",len(self.descriptions),"/",len(self.values),"/",len(self.units)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号