当前位置: 首页>>代码示例>>Python>>正文


Python mysql.DBConnection类代码示例

本文整理汇总了Python中db_.mysql.DBConnection的典型用法代码示例。如果您正苦于以下问题:Python DBConnection类的具体用法?Python DBConnection怎么用?Python DBConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DBConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_timestamp

def add_timestamp():
    db = DBConnection().db
    redis = MyRedis()
    
    e_sql = 'select id, tid, timestamp, lid from T_EVENT where timestamp = 0 order by id desc  limit 3000000'
    #e_sql = 'select id, tid, timestamp, lid from T_EVENT where timestamp = 0 '
    #e_sql = 'select id, tid, timestamp, lid from T_EVENT where timestamp = 0 limit 1000000'
    l_sql = 'select id, tid, timestamp from T_LOCATION where id = %s'
    print 'e_sql', e_sql
    event = db.query(e_sql)
    print 'len ', len(event)
    for i, e in enumerate(event):
        if not (i % 10000):
            print 'now, it is ', i
            time.sleep(2)

        print '-----i: %s, e: %s' % (i, e)

        lid = e.lid
        eid = e.id
         
        location = db.get(l_sql, lid)
        if location:
            gps_time = location.get('timestamp', 0)  
            if gps_time:
                print 'update time', gps_time
                db.execute('UPDATE T_EVENT SET timestamp = %s WHERE id = %s',
                           gps_time, eid)
开发者ID:jcsy521,项目名称:ydws,代码行数:28,代码来源:add_timestamp_event.py

示例2: batch_import

def batch_import(file_path):
    db = DBConnection().db
    wb = xlrd.open_workbook(file_path)
    sheet = wb.sheets()[0]
    lst = ""
    num = 0
    for i in range(sheet.nrows):
        row = sheet.row_values(i)
        mobile = unicode(row[0])
        mobile = mobile[0:11]
        t = db.get('select id, mobile, login, tid,owner_mobile,domain from T_TERMINAL_INFO where mobile = %s', mobile)
        if not t:
            num += 1
            print 'not: ', mobile
            db.execute("INSERT INTO T_BIZ_WHITELIST(id, mobile)"
                       "  VALUES(NULL, %s)"
                       "  ON DUPLICATE KEY"
                       "  UPDATE mobile = values(mobile)", mobile)
        else:
            print 't', t


        #lst += "'" + mobile + "',"
        #print 'select id, mobile, login, tid,owner_mobile,domain from T_TERMINAL_INFO where mobile = ' + mobile + ';'
        #db.execute("INSERT INTO T_BIZ_WHITELIST(id, mobile)"
        #           "  VALUES(NULL, %s)"
        #           "  ON DUPLICATE KEY"
        #           "  UPDATE mobile = values(mobile)", mobile)
        #content = ':SIM ' + umobile + ':' + mobile
        #print content
        #SMSHelper.send_to_terminal(mobile, content)
        #print '%s sucessfully.' % mobile
    print num 
开发者ID:jcsy521,项目名称:ydws,代码行数:33,代码来源:import_whitelist_pure.py

示例3: move_data

def move_data():
    db = DBConnection().db
       
    mobiles = ['18310505991', '13693675352', '13581731204']
    message = "数据库T_LOCATION已经完全转移到T_LOCATION_NEW,请及确认表信息的正确性和完整性。"
    #max_row = 1000000000
    max_row = 250000000
    begin_time = time.gmtime(time.time())
    for i in range(10000, max_row, 10000):
        sql = "INSERT INTO T_LOCATION_NEW" \
              " SELECT * FROM T_LOCATION WHERE id <=%d AND id > %d -10000" \
              " and (timestamp between 0 and 1448899200)" % (i, i)
        logging.info("exectue sql:%s", sql)
        
        n = db.execute(sql)
        #time.sleep(0.1)
        logging.info("last record  row id =%s", n)
        break
       # if i = 250000000:
        if i == 240000000:
            for mobile in mobiles:
                SMSHelper.send(mobile, message)    
                print "send", mobile
    end_time = time.gmtime(time.time())
    L_bak = "alter table T_LOCATION rename  to T_LOCATION_bak"
    NEW_L = "alter table T_LOCATION_NEW rename  to T_LOCATION"
    
    for i in range(1, 5): 
        time.sleep(1)
        logging.info("Will rename table neame after %d second", 5-i)
    
    db.execute(L_bak)
    db.execute(NEW_L)
    logging.info("exchange tables T_LOCATION and T_LOCATION_NEW is accomplished ")
    logging.info("Move table data begin_time:%s, end_time:%s", begin_time, end_time)
开发者ID:jcsy521,项目名称:ydws,代码行数:35,代码来源:move_table_location.py

示例4: add_whitelist

def add_whitelist():
    db = DBConnection().db
    begin = 20000000000
    num = 100
    for mobile  in xrange(begin, begin+num+1):
        print 'mobile', mobile
        db.execute("INSERT INTO T_BIZ_WHITELIST(id, mobile)"
                   "  VALUES(NULL, %s)"
                   "  ON DUPLICATE KEY"
                   "  UPDATE mobile = values(mobile)", mobile)
开发者ID:jcsy521,项目名称:ydws,代码行数:10,代码来源:add_whitelist.py

示例5: MOACB

class MOACB(object):
    
    
    def __init__(self):
        ConfHelper.load(options.conf)
        self.db = DBConnection().db
    
    
    def fetch_mo_sms(self):
        status = ErrorCode.SUCCESS
        result = None
        try:
            mos = self.db.query("SELECT id, msgid, mobile, content "
                                "  FROM T_SMS "
                                "  WHERE category = %s "
                                "  AND send_status = %s"
                                "  ORDER BY id ASC"
                                "  LIMIT 10",
                                SMS.CATEGORY.MO, SMS.SENDSTATUS.PREPARING)
            
            for mo in mos:
                mobile = mo["mobile"]
                content = mo["content"]
                id = mo["id"]
                msgid = mo["msgid"]
                
                result = self.send_mo_to_acb(mobile, content, msgid)
                if result["status"] == ErrorCode.SUCCESS:
                    if int(result["ret"]) == ErrorCode.SUCCESS:
                        logging.info("SMS-->ACB success mobile = %s, content = %s", mobile, content)
                        self.db.execute("UPDATE T_SMS "
                                       "  SET send_status = %s"
                                       "  WHERE id = %s",
                                       SMS.SENDSTATUS.SUCCESS, id)
                        status = ErrorCode.SUCCESS
                    elif int(result["ret"]) == ErrorCode.FAILED:
                        logging.info("SMS-->ACB failure mobile = %s, content = %s", mobile, content)
                        self.db.execute("UPDATE T_SMS "
                                       "  SET send_status = %s"
                                       "  WHERE id = %s",
                                       SMS.SENDSTATUS.FAILURE, id)
                        status = ErrorCode.FAILURE
                    else:
                        #sms-->acb reponse error result
                        status = ErrorCode.FAILURE
                else:
                    # http response is None
                    status = ErrorCode.FAILURE
            
        except Exception, msg:
            status = ErrorCode.FAILURE
            logging.exception("Fetch mo sms exception : %s", msg)
        finally:
开发者ID:jcsy521,项目名称:ydws,代码行数:53,代码来源:moacb.py

示例6: wash_location

def wash_location():
    db = DBConnection().db
    redis = MyRedis()
    
    #sql = "select id, tid,  mobile, owner_mobile, begintime, login_time from T_TERMINAL_INFO where tid = '36E2400480' "
    sql = "select id, tid,  mobile, owner_mobile, begintime, login_time from T_TERMINAL_INFO"
    #sql = "select id, tid,  mobile, owner_mobile, begintime, login_time from T_TERMINAL_INFO where login = 0"
    #print 'sql', sql
    terminals  = db.query(sql)
    print 'len ', len(terminals)
    count = 0
    cnt = 0
    for i, t in enumerate(terminals):
        tid = t.tid
        key = 'location:%s' % tid
        location = redis.get(key) 
        if not location:
        #if True:
            print 'tid', tid

            location = db.get("SELECT timestamp, MAX(timestamp) as maxtime"
                              "  FROM T_LOCATION"
                              "  WHERE tid = %s"
                              "    AND type = 0"
                              "    AND latitude != 0",
                              tid)
            
            if location:
                if location.timestamp != location.maxtime:
                    print 'timestamp != maxtime, tid', tid
                    location = db.get("SELECT * FROM T_LOCATION where timestamp = %s AND tid = %s limit 1", location.maxtime, tid)
                else:
                    continue
                mem_location = DotDict({'id':location.id,
                                        'latitude':location.latitude,
                                        'longitude':location.longitude,
                                        'type':location.type,
                                        'clatitude':location.clatitude,
                                        'clongitude':location.clongitude,
                                        'timestamp':location.timestamp,
                                        'name':location.name,
                                        'degree':float(location.degree),
                                        'speed':float(location.speed),
                                        'locate_error':int(location.locate_error)})

                redis.setvalue(key, mem_location, 86400*356*2)
                count = count +1 
                print 'handled tid:', tid
            else:
                cnt = cnt + 1    
    print 'total hanlded count:', count
    print 'total not hanlded count:', cnt
开发者ID:jcsy521,项目名称:ydws,代码行数:52,代码来源:wash_location.py

示例7: statistic

def statistic():
    db = DBConnection().db
    sql = 'select from_unixtime(timestamp), terminal_online, terminal_offline from T_STATISTIC where type=2 and  timestamp between  1378051140  and 1380556741'

    t = db.query(sql)
    sum_on = 0
    sum_off = 0
    for i in t:  
        print 'i', i
        on = i.terminal_online
        off = i.terminal_offline
        sum_on += on
        sum_off += off 
    print 'sum_on: %s, sum_off: %s, sum: %s' % (sum_on, sum_off, sum_on+sum_off)
开发者ID:jcsy521,项目名称:ydws,代码行数:14,代码来源:statistic.py

示例8: execute

def execute():
    db = DBConnection().db
    redis = MyRedis()
    terminals = db.query("SELECT tid, mobile FROM T_TERMINAL_INFO ")
    print "len ", len(terminals)
    for t in terminals:
        tid = t.tid
        print "tid", tid
        car = db.get("select * from T_CAR where tid = %s", tid)
        if car:
            print "has car "
            pass
        else:
            print "insert car"
开发者ID:jcsy521,项目名称:ydws,代码行数:14,代码来源:add_car.py

示例9: modify_terminal

def modify_terminal():

    db = DBConnection().db
    redis = MyRedis()
    
    mobile='14778746907'
    #mobile='14778741845'
    #mobile='14778749172'
    #mobile='14778746786'
    #mobile='14778740942'
    #mobile='14778745985'
    #mobile='14778744628'
    #mobile='14778744861'
    #mobile='14778742261'
    #mobile='14778744473'
    #mobile='14778747112'
    #mobile='14778745219'
    #mobile='14778742290'
    #mobile='14778749137'
    #mobile='14778742587'
    #mobile='14778745073'
    #mobile='14778747467'
    #mobile='14778741340'
    #mobile='14778748943'
    #mobile='14778743681'
    sql = "select id, tid, mobile, owner_mobile, begintime, login_time from T_TERMINAL_INFO where mobile= %s"
    
    terminals  = db.query(sql, mobile)
    #print 'len ', len(terminals)
    count = 0
    cnt = 0
    no_loc = 0
    for i, t in enumerate(terminals):
        tid = t.tid
        mobile = t.mobile
        owner_mobile = t.owner_mobile
        terminal_info_key = get_terminal_info_key(tid) 
        terminal_info = redis.getvalue(terminal_info_key) 
        if terminal_info: 
            print 'umobile in redis:%s, umobile in db:%s' % (terminal_info['owner_mobile'], owner_mobile)
            if terminal_info['owner_mobile'] != owner_mobile:
                print 'mobile: %s, umobile in redis:%s, umobile in db:%s' % (mobile, terminal_info['owner_mobile'], owner_mobile)
                cnt = cnt + 1    
                terminal_info['owner_mobile'] = owner_mobile 
                redis.setvalue(terminal_info_key, terminal_info)
        else:
            pass

    print 'count:', count
    print 'cnt:', cnt
开发者ID:jcsy521,项目名称:ydws,代码行数:50,代码来源:update_owner_mobile_in_redis.py

示例10: send_all

def send_all(content):
    db = DBConnection().db

    terminals = db.query("SELECT * FROM V_TERMINAL WHERE cid in ( '15207610001' )")
    # terminals = db.query("select id, tid, mobile, offline_time, from_unixtime(offline_time) from T_TERMINAL_INFO where login = 0")
    # terminals = db.query("SELECT mobile FROM T_TERMINAL_INFO where login=0")
    # terminals = db.query("select id, tid, mobile, offline_time, from_unixtime(offline_time) from T_TERMINAL_INFO where login = 0")
    # terminals = db.query("select id, tid, mobile, offline_time, from_unixtime(offline_time) from T_TERMINAL_INFO where login = 0 and offline_time>1408197915")
    # terminals = db.query("select id, tid, mobile, offline_time, from_unixtime(offline_time) from T_TERMINAL_INFO where login = 0 and offline_time>1411452000")
    print "len: %s", len(terminals)

    for t in terminals:
        terminal = db.get("select login, tid, mobile from T_TERMINAL_INFO where tid = %s", t.tid)
        if terminal.login == 0:  # offline
            print "--", terminal
            send(content, terminal.mobile)
开发者ID:jcsy521,项目名称:ydws,代码行数:16,代码来源:send_sms.py

示例11: MGroupMixin

class MGroupMixin(object):

    def __init__(self):
        self.mysql_db = DBConnection().db

    def retrieve_mixin(self, citylist=None):
        results = []
        for city in citylist:
            infos = self.mysql_db.query("SELECT thp.province_id AS id, thp.province_name AS province_name,"
                                        "       thc.city_name AS city_name"
                                        "  FROM T_HLR_CITY AS thc, T_HLR_PROVINCE AS thp"
                                        "  WHERE thc.region_code = %s"
                                        "    AND thc.province_id = thp.province_id", city)
            for info in infos:
                groups = self.mysql_db.query("SELECT txg.id, txg.xxt_id, txg.name,"
                                             " txa.xxt_id AS agency_id, txa.name AS agency_name"
                                             " FROM T_XXT_GROUP AS txg LEFT JOIN T_XXT_AGENCY AS txa"
                                             "   ON txa.xxt_id = txg.agency_id"
                                             " WHERE txg.city_id = %s", city)
                for group in groups:
                    #total_parents = self.mysql_db.get("SELECT count(*) AS total"
                    #                                  " FROM T_XXT_USER AS txu"
                    #                                  " WHERE txu.group_id = %s", group.xxt_id)
                    total_parents = self.mysql_db.get("call P_GROUP_TOTAL_PARENTS(%s)",
                                                      group.xxt_id) 
                    #total_children = self.mysql_db.get("SELECT count(*) AS total"
                    #                                   " FROM T_XXT_TARGET AS txt"
                    #                                   " WHERE txt.group_id = %s", group.xxt_id)
                    total_children = self.mysql_db.get("call P_GROUP_TOTAL_CHILDREN(%s)",
                                                       group.xxt_id) 
                    if not group.agency_name:
                        group.agency_name = u'暂无'

                    res = {'_id': None,
                           'province_id': info.id,
                           'city_id': city,
                           'id': group.id,
                           'group_id': group.xxt_id,
                           'group_name': group.name,
                           'agency_id': group.agency_id,
                           'agency': group.agency_name,
                           'total_parents': total_parents.total,
                           'total_children': total_children.total,
                           'city': info.city_name,
                           'province': info.province_name}
                    results.append(res)
        return results
开发者ID:jcsy521,项目名称:ydws,代码行数:47,代码来源:mgroup.py

示例12: MLocationMixin

class MLocationMixin(object):
   
    def __init__(self):
        self.mysql_db = DBConnection().db
 
    def retrieve_mixin(self, city_list=None, start_time=None, end_time=None):
       
        results = []
        d = datetime.date.fromtimestamp(start_time/1000)
        year = d.year
        month = d.month
        cities = city_info(city_list, self.mysql_db)
        for city in cities:
            groups = self.mysql_db.query("SELECT T_XXT_GROUP.name as group_name, T_XXT_GROUP.xxt_id"
                                         " FROM T_XXT_GROUP WHERE T_XXT_GROUP.city_id = %s",
                                         city.id)
            for group in groups: 
                for item, category in [ #('custom', LOCATION.CATEGORY.CUSTOM),
                                       ('schedule', LOCATION.CATEGORY.SCHEDULE),
                                       ('realtime', LOCATION.CATEGORY.REALTIME)]:
                    #data = self.mysql_db.get("SELECT count(T_LOCATION.id) as total"
                    #                         " FROM T_LOCATION, T_XXT_TARGET, T_LBMP_TERMINAL"
                    #                         " WHERE T_LOCATION.timestamp BETWEEN %s AND %s" 
                    #                         " AND T_LOCATION.category = %s"
                    #                         " AND T_LOCATION.sim = T_LBMP_TERMINAL.sim"
                    #                         " AND T_LBMP_TERMINAL.sim = T_XXT_TARGET.mobile"
                    #                         " AND T_XXT_TARGET.group_id = %s",
                    #                         start_time, end_time, category, group.xxt_id)
                    data = self.mysql_db.get("call P_LOCATION(%s, %s, %s, %s)",
                                             start_time, end_time, category, group.xxt_id) 
                    group[item] = data.total

                res = {'_id': None,
                       'province_id': city.p_id,
                       'city_id': city.id,
                       'group_id': group.xxt_id,
                       'province': city.p_name,
                       'city': city.name,
                       'group_name': group.group_name,
                       # 'custom': group.custom,
                       'schedule': group.schedule,
                       'realtime': group.realtime,
                       'year': year,
                       'month': month}
                results.append(res)
        return results
开发者ID:jcsy521,项目名称:ydws,代码行数:46,代码来源:mlocation.py

示例13: block_test

def block_test():
    db = DBConnection().db
    redis = MyRedis()

    sms = db.query("SELECT uid FROM T_SMS_OPTION")
    count = 0
    for s in sms:
        uid = s.uid
        user = db.get("select * from T_USER where uid = %s", uid)
        if user:
            pass
            # print 'pass'
        else:
            db.execute("DELETE FROM T_SMS_OPTION WHERE uid = %s", uid)
            print "delete ....", uid
            count += 1
    print "-------count: %s" % count
开发者ID:jcsy521,项目名称:ydws,代码行数:17,代码来源:fix_sms_option.py

示例14: block_test

def block_test():
    db = DBConnection().db
    redis = MyRedis()

    #terminals = db.query("SELECT tid, mobile, group_id, cid FROM V_TERMINAL WHERE group_id != '-1'")
    #terminals = db.query("SELECT tid, tmobile, group_id, cid FROM V_TERMINAL WHERE cid = '13600335550'")
    #terminals = db.query("SELECT tid, mobile, group_id FROM T_TERMINAL_INFO WHERE stop_interval != 0 limit 1000")
    print 'len ', len(terminals)
    for terminal in terminals: 
        tid = terminal.tid
        db.execute("UPDATE T_TERMINAL_INFO SET stop_interval=0 WHERE tid = %s", 
                   tid)
        print 'tid: %s stop_interval is closed.' % tid
        sessionID_key = get_terminal_sessionID_key(tid)
        old_sessionid = redis.get(sessionID_key)
        if old_sessionid:
            redis.delete(sessionID_key)
            print "Termianl %s delete session in redis." % tid
开发者ID:jcsy521,项目名称:ydws,代码行数:18,代码来源:no_stop_interval.py

示例15: block_test

def block_test():
    db = DBConnection().db
    redis = MyRedis()

    #terminals = db.query("select tid from T_TERMINAL_INFO where group_id= '438';")
    #terminals = db.query("select tid from T_TERMINAL_INFO where group_id= '438'")
    terminals = db.query("select id, tid,  test from T_TERMINAL_INFO where mobile = '14778748087' ")
    
    for terminal in terminals: 
        tid = terminal.tid
        #db.execute("UPDATE T_TERMINAL_INFO SET trace_para='60:0' WHERE tid = %s", 
        #           tid)
        #print 'tid: %s test is closed.' % tid
        sessionID_key = get_terminal_sessionID_key(tid)
        old_sessionid = redis.get(sessionID_key)
        if old_sessionid:
            redis.delete(sessionID_key)
            print "Termianl %s delete session in redis." % tid
开发者ID:jcsy521,项目名称:ydws,代码行数:18,代码来源:trace_parm.py


注:本文中的db_.mysql.DBConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。