Exemple #1
0
def main():
    db = DB_connection('localhost', 3306, 'root', 'bwx0605', 'All_Scraper',
                       'utf8')
    conn = db.connects()
    mapper = DB_operation(conn)
    sql_select_sku_shop_id = 'SELECT sku,shop_id FROM All_Scraper.jd_products;'
    result = mapper.select(sql_select_sku_shop_id)
    for item in result:
        sku = item[0]
        shop_id = item[1]
        print sku
        print shop_id
    conn.commit()
    conn.close()
Exemple #2
0
def products_update_operation_1(data, shop_name):
    try:
        db = DB_connection('localhost', 3306, 'root', 'bwx0605', 'All_Scraper',
                           'utf8')
        conn = db.connects()
        mapper = DB_operation(conn)
        sql_update_joint = products_update_sql_joint_1(data, shop_name)
        print("##################################################")
        print sql_update_joint
        mapper.update(sql_update_joint)
        conn.commit()
        conn.close()
    except Exception as err:
        print err
Exemple #3
0
def products_update_select(shop_id):
    # 从jd_products表中选出sku和shop_id两个字段所对应的值
    # 因为jd_products表中的一部分字段的数据是从jd_keywords解析之后插入到jd_products表中
    # 所以我们要对jd_products中的数据进行更新操作(由shop_name,shop_id,shop_name即可确认唯一一条记录)
    # 如果存在则直接更新剩余空闲字段,如果不存在则插入新的一条记录
    # 数据库连接及更新操作
    try:
        db = DB_connection('localhost', 3306, 'root', 'bwx0605', 'All_Scraper',
                           'utf8')
        conn = db.connects()
        mapper = DB_operation(conn)
        sql_select_shop_id = 'SELECT shop_id FROM All_Scraper.jd_products where `shop_id`=' + shop_id
        result = mapper.select(sql_select_shop_id)
        return result
    except Exception as err:
        print err
Exemple #4
0
def products_insert_operation(data):
    try:
        db = DB_connection('localhost', 3306, 'root', 'bwx0605', 'All_Scraper',
                           'utf8')
        conn = db.connects()
        mapper = DB_operation(conn)
        (sql_insert_joint,
         sql_insert_joint_iamge) = products_insert_sql_joint(data)
        print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
        print sql_insert_joint
        print sql_insert_joint_iamge
        print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
        mapper.insert(sql_insert_joint)
        mapper.insert(sql_insert_joint_iamge)
        conn.commit()
        conn.close()
    except Exception as err:
        print err
Exemple #5
0
def keywords_match():
    try:
        # 连接数据库
        db = DB_connection('localhost', 3306, 'root', 'bwx0605', 'Scraper', 'utf8')
        conn = db.connects()
        mapper = DB_operation(conn)
        sql_select_keywords='SELECT keyword FROM Scraper.search_keywords;'
        all_keywords = mapper.select(sql_select_keywords)
        conn.commit()
        conn.close()
        keywords=[]
        for keyword in all_keywords:
            keyword=keyword[0].encode("utf-8")
            J= re.sub('[A-Za-z0-9\[\`\~\!\@\-\.\#\$\^\&\*\(\)\=\|\{\}\'\:\;\'\,\[\]\.\<\>\/\?\~\!\@\#\\\&\*\%]', '',keyword)
            keywords.append(J)
            # S = urllib.quote(J.decode(sys.stdin.encoding).encode('utf8'))
    except Exception as err:
        print err