Example #1
0
def updateItemProps():
    db = getDBConn('ibbd')
    c = db.cursor()
    c.execute(
        'SELECT DISTINCT(cid) FROM ibbd.lib_topitemcats WHERE is_parent=0')
    cidList = c.fetchall()
    c.close()
    for (i, cid) in enumerate(cidList):
        if i <= 5010:
            continue
        metadata = json.loads(getItemProps(cid[0]))
        if not metadata.has_key('itemprops_get_response'):
            print json.dumps(metadata, indent=4)
            break
        if not metadata['itemprops_get_response'].has_key('item_props'):
            continue
        metadata = metadata['itemprops_get_response']['item_props'][
            'item_prop']
        for item_prop in metadata:
            print json.dumps(item_prop, indent=4, ensure_ascii=False)
            if not item_prop.has_key('prop_values'):
                continue
            for prop_value in item_prop['prop_values']['prop_value']:
                cmdStr = \
                    "INSERT INTO lib_topitem_props VALUES('{0}',CURDATE(),'{1}','{2}','{3}','{4}')".format(cid[0],
                        item_prop['pid'], escapeSQLCommand(item_prop['name'
                        ].encode('utf-8')), prop_value['vid'],
                        escapeSQLCommand(prop_value['name'].encode('utf-8')))
                db.query(cmdStr)
    db.commit()
    db.close()
Example #2
0
def updateItemProps():
    db = getDBConn('ibbd')
    c = db.cursor()
    c.execute('SELECT DISTINCT(cid) FROM ibbd.lib_topitemcats WHERE is_parent=0'
              )
    cidList = c.fetchall()
    c.close()
    for (i, cid) in enumerate(cidList):
        if i <= 5010:
            continue
        metadata = json.loads(getItemProps(cid[0]))
        if not metadata.has_key('itemprops_get_response'):
            print json.dumps(metadata, indent=4)
            break
        if not metadata['itemprops_get_response'].has_key('item_props'):
            continue
        metadata = metadata['itemprops_get_response']['item_props']['item_prop']
        for item_prop in metadata:
            print json.dumps(item_prop, indent=4, ensure_ascii=False)
            if not item_prop.has_key('prop_values'):
                continue
            for prop_value in item_prop['prop_values']['prop_value']:
                cmdStr = \
                    "INSERT INTO lib_topitem_props VALUES('{0}',CURDATE(),'{1}','{2}','{3}','{4}')".format(cid[0],
                        item_prop['pid'], escapeSQLCommand(item_prop['name'
                        ].encode('utf-8')), prop_value['vid'],
                        escapeSQLCommand(prop_value['name'].encode('utf-8')))
                db.query(cmdStr)
    db.commit()
    db.close()
Example #3
0
def saveUserRateList(metadata, connpool=connpool):
    dbConn = connpool.get_connection()
    c = dbConn.cursor()
    for data in metadata:
        cmd = 'INSERT IGNORE INTO %s values(%s, NOW())' % (mapping_userratelist['table'
                                                                                ], '$VALUE$')
        v = ''
        for key in mapping_userratelist['fields']:
            if data[key]:
                v = v + "'%s'," % escapeSQLCommand(str(data[key]))
            else:
                v = v + 'null, '
        cmd = cmd.replace('$VALUE$', v[:v.rindex(',')])
        c.execute(cmd)
        for spuRate in data['spuRatting']:
            cmd = \
                "INSERT IGNORE INTO {0} values('{1}','{2}','{3}','{4}','{5}')".format(
                'top_user_rate_spurating',
                data['rateId'],
                spuRate['XID'],
                spuRate['name'],
                spuRate['value'],
                spuRate['desc'],
                )
            c.execute(cmd)
    dbConn.commit()
    c.close()
    connpool.release(dbConn)
Example #4
0
def saveUserRateList(metadata, connpool=connpool):
    dbConn = connpool.get_connection()
    c = dbConn.cursor()
    for data in metadata:
        cmd = "INSERT IGNORE INTO %s values(%s, NOW())" % (mapping_userratelist["table"], "$VALUE$")
        v = ""
        for key in mapping_userratelist["fields"]:
            if data[key]:
                v = v + "'%s'," % escapeSQLCommand(str(data[key]))
            else:
                v = v + "null, "
        cmd = cmd.replace("$VALUE$", v[: v.rindex(",")])
        c.execute(cmd)
        for spuRate in data["spuRatting"]:
            cmd = "INSERT IGNORE INTO {0} values('{1}','{2}','{3}','{4}','{5}')".format(
                "top_user_rate_spurating",
                data["rateId"],
                spuRate["XID"],
                spuRate["name"],
                spuRate["value"],
                spuRate["desc"],
            )
            c.execute(cmd)
    dbConn.commit()
    c.close()
    connpool.release(dbConn)
Example #5
0
def saveTopItem(d, connpool=connpool):
    dbConn = connpool.get_connection()
    cmd = "INSERT INTO %s values(%s,NOW())" % (mapping_topitem["table"], "$VALUE$")
    v = ""
    for key in mapping_topitem["fields"]:
        if d[key]:
            v = v + "'%s', " % escapeSQLCommand(d[key])
        else:
            v = v + "null, "
    cmd = cmd.replace("$VALUE$", v[:-2])
    dbConn.query(cmd)
    dbConn.commit()
    connpool.release(dbConn)
Example #6
0
def saveTopItem(d, connpool=connpool):
    dbConn = connpool.get_connection()
    cmd = 'INSERT INTO %s values(%s,NOW())' % (mapping_topitem['table'],
                                                      '$VALUE$')
    v = ''
    for key in mapping_topitem['fields']:
        if d[key]:
            v = v + "'%s', " % escapeSQLCommand(d[key])
        else:
            v = v + 'null, '
    cmd = cmd.replace('$VALUE$', v[:-2])
    dbConn.query(cmd)
    dbConn.commit()
    connpool.release(dbConn)
Example #7
0
def saveTopRate(infos, connpool=connpool):
    dbConn = connpool.get_connection()
    for data in infos:
        cmd = "INSERT IGNORE INTO %s values(%s,NOW())" % (mapping_toprate["table"], "$VALUE$")
        v = ""
        for li in data:
            if li:
                v = v + "'%s', " % escapeSQLCommand(li)
            else:
                v = v + "null, "
        cmd = cmd.replace("$VALUE$", v[:-2])
        dbConn.query(cmd)
    dbConn.commit()
    connpool.release(dbConn)
Example #8
0
def saveTopRate(infos, connpool=connpool):
    dbConn = connpool.get_connection()
    for data in infos:
        cmd = 'INSERT IGNORE INTO %s values(%s,NOW())' % (mapping_toprate['table'],
                                                          '$VALUE$')
        v = ''
        for li in data:
            if li:
                v = v + "'%s', " % escapeSQLCommand(li)
            else:
                v = v + 'null, '
        cmd = cmd.replace('$VALUE$', v[:-2])
        dbConn.query(cmd)
    dbConn.commit()
    connpool.release(dbConn)
Example #9
0
def updateItemCats():
    r = redis.StrictRedis(host='223.4.5.116')
    db = getDBConn('ibbd')
    r.lpush('itemCats', 0)
    while 1:
        if r.llen('itemCats') == 0:
            break
        cat = r.lpop('itemCats')
        metadata = json.loads(getItemCats(cat), encoding='utf-8'
                              )['itemcats_get_response']['item_cats']['item_cat'
                ]
        print json.dumps(metadata, indent=4, ensure_ascii=False)
        for t in metadata:
            cmdStr = \
                "INSERT INTO lib_topitemcats VALUES('{0}','{1}',{2},'{3}','{4}')".format(t['cid'
                    ], escapeSQLCommand(t['name'].encode('utf-8')),
                    t['is_parent'], t['parent_cid'], t['sort_order'])
            db.query(cmdStr)
            if t['is_parent']:
                r.lpush('itemCats', t['cid'])
    db.commit()
    db.close()
Example #10
0
def updateItemCats():
    r = redis.StrictRedis(host='223.4.5.116')
    db = getDBConn('ibbd')
    r.lpush('itemCats', 0)
    while 1:
        if r.llen('itemCats') == 0:
            break
        cat = r.lpop('itemCats')
        metadata = json.loads(
            getItemCats(cat),
            encoding='utf-8')['itemcats_get_response']['item_cats']['item_cat']
        print json.dumps(metadata, indent=4, ensure_ascii=False)
        for t in metadata:
            cmdStr = \
                "INSERT INTO lib_topitemcats VALUES('{0}','{1}',{2},'{3}','{4}')".format(t['cid'
                    ], escapeSQLCommand(t['name'].encode('utf-8')),
                    t['is_parent'], t['parent_cid'], t['sort_order'])
            db.query(cmdStr)
            if t['is_parent']:
                r.lpush('itemCats', t['cid'])
    db.commit()
    db.close()