예제 #1
0
    def load_dbf(self, tableName, row2obj=None):
        if row2obj is None:
            row2obj = getattr(self, 'load_' + tableName[-3:].lower())
        fn = self.dbpath
        if self.archive_name is not None:
            if tableName in self.archived_tables:
                fn = os.path.join(fn, self.archive_name)
        fn = os.path.join(fn, tableName)
        fn += self.table_ext
        if self.use_dbf_py:
            dblogger.info("Loading %s...", fn)
            import dbf  # http://pypi.python.org/pypi/dbf/
            #~ table = dbf.Table(fn)
            table = dbf.Table(fn, codepage=self.codepage)
            #~ table.use_deleted = False
            table.open()
            #~ print table.structure()
            dblogger.info("Loading %d records from %s (%s)...",
                          len(table), fn, table.codepage)
            for record in table:
                if not dbf.is_deleted(record):
                    yield row2obj(record)
                    # i = row2obj(record)
                    # if i is not None:
                    #     yield settings.TIM2LINO_LOCAL(tableName, i)
            table.close()
        else:
            f = dbfreader.DBFFile(fn, codepage="cp850")
            dblogger.info("Loading %d records from %s...", len(f), fn)
            f.open()
            for dbfrow in f:
                i = row2obj(dbfrow)
                if i is not None:
                    yield settings.TIM2LINO_LOCAL(tableName, i)
            f.close()

        self.after_load(tableName)
예제 #2
0
파일: utils.py 프로젝트: khchine5/xl
    def load_dbf(self, tableName, row2obj=None):
        if row2obj is None:
            row2obj = getattr(self, 'load_' + tableName[-3:].lower())
        fn = self.dbpath
        if self.archive_name is not None:
            if tableName in self.archived_tables:
                fn = os.path.join(fn, self.archive_name)
        fn = os.path.join(fn, tableName)
        fn += dd.plugins.tim2lino.dbf_table_ext
        count = 0
        if dd.plugins.tim2lino.use_dbf_py:
            dd.logger.info("Loading %s...", fn)
            import dbf  # http://pypi.python.org/pypi/dbf/
            # table = dbf.Table(fn)
            table = dbf.Table(fn, codepage=self.codepage)
            # table.use_deleted = False
            table.open()
            # print table.structure()
            dd.logger.info("Loading %d records from %s (%s)...",
                           len(table), fn, table.codepage)
            for record in table:
                if not dbf.is_deleted(record):
                    try:
                        yield row2obj(record)
                        count += 1
                    except Exception as e:
                        traceback.print_exc()
                        dd.logger.warning(
                            "Failed to load record %s from %s : %s",
                            record, tableName, e)

                    # i = row2obj(record)
                    # if i is not None:
                    #     yield settings.TIM2LINO_LOCAL(tableName, i)
            table.close()
        elif dd.plugins.tim2lino.use_dbfread:
            dd.logger.info("Loading readonly %s...", fn)
            from dbfread import DBF
            dbf = DBF(fn)
            for record in dbf:
                d = { f.name.lower() : record[f.name] for f in dbf.fields}
                d = AttrDict(d)
                try:
                    yield row2obj(d)
                    count += 1
                except Exception as e:
                    dd.logger.warning(
                        "Failed to load record %s from %s : %s",
                        record, tableName, e)

        else:
            f = dbfreader.DBFFile(fn, codepage="cp850")
            dd.logger.info("Loading %d records from %s...", len(f), fn)
            f.open(deleted=True)
            # must set deleted=True and then filter them out myself
            # because big tables can raise
            # RuntimeError: maximum recursion depth exceeded in cmp
            for dbfrow in f:
                if not dbfrow.deleted():
                    try:
                        i = row2obj(dbfrow)
                        if i is not None:
                            yield settings.TIM2LINO_LOCAL(tableName, i)
                            count += 1
                    except Exception as e:
                        traceback.print_exc()
                        dd.logger.warning(
                            "Failed to load record %s : %s", dbfrow, e)
            f.close()

        dd.logger.info(
            "{} rows have been loaded from {}.".format(count, fn))
        self.after_load(tableName)
예제 #3
0
#rec=[list(x) for x in cur]
#count=1
#for x in xrange(0,len(rec)):
#        rec[x][1]=count
#	count+=1
#for x in rec:
#	query = """ UPDATE inf_images_objects SET imgo_id = %s where imgo_id = %s """
#	data = ( x[1] , x[0] )
#	cur.execute(query,data)
#	conn.commit
#########################sync image with plu prefix in name############################

sysaddr = dbf.Table('./origin/sysaddr.dbf')
sysaddr.open()
for x in sysaddr:
    if dbf.is_deleted(x) == False:
        cur.execute("""INSERT INTO inf_outlets (
				olet_id,
				olet_name_l1,
				olet_name_l2,
				olet_name_l3,
				olet_code,
				olet_addr_l1,
				olet_addr_l2,
				olet_addr_l3,
				olet_phone,
				olet_them_id,
				olet_date_format)
			VALUES
				(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
			ON DUPLICATE KEY UPDATE
예제 #4
0
파일: vncast.py 프로젝트: sunlei213/CATS
    def process_prices(self):
        """获取价格推送"""

        while self.active:
            # 首先获取上海市场的行情
            if self._is_reqhq:
                try:
                    self._sh_db.open()
                    hq_list = [rec for rec in self._sh_db]
                    self._sh_db.close()
                except Exception as e:
                    self.onError('打开上海行情库失败,错误信息:{0}'.format(str(e)), 0, True)
                    hq_list = []
                sh_time = ''
                today = ''
                now_time = datetime.now()
                for n, record in enumerate(hq_list):
                    tick = dict()
                    if len(record):
                        if n == 0:
                            today = str(int(record.s6))
                            time1 = record.s2.strip()
                            sh_time = '{0}:{1}:{2}'.format(
                                time1[:2], time1[2:4], time1[-2:])
                            continue
                        if dbf.is_deleted(record):
                            continue
                        tick['TradingDay'] = today
                        tick['UpdateTime'] = sh_time
                        tick['datetime'] = now_time
                        tick['symbol'] = record.s1.strip()
                        tick['exchange'] = 'SH'
                        tick['vtSymbol'] = '.'.join([tick['symbol'], 'SH'])

                        tick['lastPrice'] = record.s8
                        tick['volume'] = record.s11
                        tick['openPrice'] = record.s4
                        tick['highPrice'] = record.s6
                        tick['lowPrice'] = record.s7
                        tick['preClosePrice'] = record.s3

                        # LTS有5档行情
                        tick['buyPrice1'] = record.s9
                        tick['buyVolume1'] = record.s15
                        tick['sellPrice1'] = record.s10
                        tick['sellVolume1'] = record.s21

                        tick['buyPrice2'] = record.s16
                        tick['buyVolume2'] = record.s17
                        tick['sellPrice2'] = record.s22
                        tick['sellVolume2'] = record.s23

                        tick['buyPrice3'] = record.s18
                        tick['buyVolume3'] = record.s19
                        tick['sellPrice3'] = record.s24
                        tick['sellVolume3'] = record.s25

                        tick['buyPrice4'] = record.s26
                        tick['buyVolume4'] = record.s27
                        tick['sellPrice4'] = record.s30
                        tick['sellVolume4'] = record.s31

                        tick['buyPrice5'] = record.s28
                        tick['buyVolume5'] = record.s29
                        tick['sellPrice5'] = record.s32
                        tick['sellVolume5'] = record.s33
                        if record.s1.strip() in self.subSymbols['SH']:
                            req = dict()
                            req['callback'] = self.on_send_mkt_data
                            req['reqID'] = 0
                            req['data'] = tick
                            self.reqQueue.put(req)
                        self._hq_dict[tick['vtSymbol']] = tick
                    if not self.active:
                        break
            # 获取深圳行情

            # 流量控制
            sleep(self.interval)
            pass
예제 #5
0
 def deleted(self, workarea=None):
     return dbf.is_deleted(
         self._get_table_info(workarea).table.current_record)
예제 #6
0
파일: utils.py 프로젝트: einarfelix/xl
    def load_dbf(self, tableName, row2obj=None):
        if row2obj is None:
            row2obj = getattr(self, 'load_' + tableName[-3:].lower())
        fn = self.dbpath
        if self.archive_name is not None:
            if tableName in self.archived_tables:
                fn = os.path.join(fn, self.archive_name)
        fn = os.path.join(fn, tableName)
        fn += dd.plugins.tim2lino.dbf_table_ext
        count = 0
        if dd.plugins.tim2lino.use_dbf_py:
            dd.logger.info("Loading %s...", fn)
            import dbf  # http://pypi.python.org/pypi/dbf/
            # table = dbf.Table(fn)
            table = dbf.Table(fn, codepage=self.codepage)
            # table.use_deleted = False
            table.open()
            # print table.structure()
            dd.logger.info("Loading %d records from %s (%s)...", len(table),
                           fn, table.codepage)
            for record in table:
                if not dbf.is_deleted(record):
                    try:
                        yield row2obj(record)
                        count += 1
                    except Exception as e:
                        traceback.print_exc()
                        dd.logger.warning(
                            "Failed to load record %s from %s : %s", record,
                            tableName, e)

                    # i = row2obj(record)
                    # if i is not None:
                    #     yield settings.TIM2LINO_LOCAL(tableName, i)
            table.close()
        elif dd.plugins.tim2lino.use_dbfread:
            dd.logger.info("Loading readonly %s...", fn)
            from dbfread import DBF
            dbf = DBF(fn)
            for record in dbf:
                d = {f.name.lower(): record[f.name] for f in dbf.fields}
                d = AttrDict(d)
                try:
                    yield row2obj(d)
                    count += 1
                except Exception as e:
                    dd.logger.warning("Failed to load record %s from %s : %s",
                                      record, tableName, e)

        else:
            f = dbfreader.DBFFile(fn, codepage="cp850")
            dd.logger.info("Loading %d records from %s...", len(f), fn)
            f.open(deleted=True)
            # must set deleted=True and then filter them out myself
            # because big tables can raise
            # RuntimeError: maximum recursion depth exceeded in cmp
            for dbfrow in f:
                if not dbfrow.deleted():
                    try:
                        i = row2obj(dbfrow)
                        if i is not None:
                            yield settings.TIM2LINO_LOCAL(tableName, i)
                            count += 1
                    except Exception as e:
                        traceback.print_exc()
                        dd.logger.warning("Failed to load record %s : %s",
                                          dbfrow, e)
            f.close()

        dd.logger.info("{} rows have been loaded from {}.".format(count, fn))
        self.after_load(tableName)
예제 #7
0
mlist_tmp.close()
mlist.close()
#why add a deleted column?
#because when update the dbf to mysql the script only update modifier modlsthd menu lu_head instead of purge mysql andsynchronize a brand new database
#so if you pack or delete dbf first the sequence of item will be messed
#this method will save some capacity and made the script a little faster
modi = dbf.Table('./origin/modifier.dbf')
modi.open()
modi.codepage = dbf.CodePage('cp936')
mod = []
#write a sequence number in first col
#only support multiplied operator if foperator col is *,then write 11st col with value x
#short circuit judge sentence none=>0 if not round with price x multiplier with nidigts
counter = 1
for x in modi:
    if dbf.is_deleted(x):
        if x['foperator'] == '*':
            mod.append(( '%6s'% counter,\
             x['fmod_num'],\
             x['fmod_desc1'],\
             x['fmod_desc2'],\
             x['fmod_desc3'],\
             0 if x['fmod_pri1'] == None else round(x['fmod_pri1']*multiplier,NDIGITS),\
             0 if x['fmod_pri2'] == None else round(x['fmod_pri2']*multiplier,NDIGITS),\
             0 if x['fmod_pri3'] == None else round(x['fmod_pri3']*multiplier,NDIGITS),\
             0 if x['fmod_pri4'] == None else round(x['fmod_pri4']*multiplier,NDIGITS),\
             0 if x['fmod_pri5'] == None else round(x['fmod_pri5']*multiplier,NDIGITS),\
             'x',\
             True\
             ))
        else: