Commit 0fc3ae3e by lichenggang

init

parent c920f231
Showing with 733 additions and 0 deletions
#!encoding:utf-8
import requests
from lxml import etree
import re
from utils.mysqlopera import MySqlOperator
operator = MySqlOperator('szlc')
headers = {
"authority": "www.szlcsc.com",
"method": "GET",
"path": "/catalog.html",
"scheme": "https",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "max-age=0",
"if-modified-since": "Wed, 13 Mar 2019 02:15:00 GMT",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"}
# 拿到所有一级二级分类数据
def get_szlc_all():
# level_name_pattern = re.compile(r'\d+\.(.*)\(.*\)')
level_name_pattern = re.compile(r'([^\(]*) \(')
level_num_pattern = re.compile(r'[^\(]*\((\d+)\)')
level2_name_pattern = re.compile(r'([^\(]*)\(')
url = 'https://www.szlcsc.com/catalog.html'
resp = requests.get(url, headers=headers)
resp.encoding = 'utf-8'
dom_html = etree.HTML(resp.text)
# cates=dom_html.xpath('//div[@class="catalog_a"]//dt/a/text()')
doms_cate = dom_html.xpath('//div[@class="item"]')
all = []
for dom in doms_cate:
per_1_cate = {}
print(dom.xpath('./a/text()')[2])
per_1_cate['name'] = level_name_pattern.findall(dom.xpath('./a/text()')[2])[0].strip()
per_1_cate['num'] = int(level_num_pattern.findall(dom.xpath('./a/text()')[2])[0])
per_1_cate['url'] = dom.xpath('./a/@href')[0]
per_1_cate['level'] = 1
per_1_cate['islast'] = 0
per_1_cate['parent_id'] = 0
doms_2cate = dom.xpath('.//div[@class="child-item"]')
per_1_cate['2_list'] = []
for dom_cate_2 in doms_2cate:
per_2_cate = {}
per_2_cate['name'] = level2_name_pattern.findall(dom_cate_2.xpath('.//a/text()')[0])[0].strip()
per_2_cate['num'] = int(level_num_pattern.findall(dom_cate_2.xpath('.//a/text()')[0])[0])
per_2_cate['url'] = dom_cate_2.xpath('.//a/@href')[0]
per_1_cate['level'] = 2
per_1_cate['islast'] = 1
per_1_cate['2_list'].append(per_2_cate)
all.append(per_1_cate)
#
return all
# 数据库所有分类的is_show设置为0
def clean_db():
with operator.db.cursor() as cursor:
sql = "update lie_category set is_show = 0"
cursor.execute(sql)
operator.db.commit()
# 拿到所有旧的分类的名字和ID
def get_old_allname_and_cat_id():
with operator.db.cursor() as cursor:
sql = "select cat_id,cat_name from lie_category "
cursor.execute(sql)
old = cursor.fetchall()
return old
# 给一级分类数据找到或者生成新ID,给二级分类找到ID
def add_cat_id(all, old):
for i in all:
for d in old:
if i['name'] in d:
i['cat_id'] = d[0]
break
for c in i['2_list']:
for g in old:
if c['name'] in g:
c['cat_id'] = g[0]
with operator.db.cursor() as cursor:
for i in all:
if i.get('cat_id'):
sql = 'UPDATE lie_category SET parent_id=%s,is_show=%s, url=%s,islast=%s,level=%s WHERE cat_id=%s'
data = (0, 1, i['url'], 0, 1, i['cat_id'])
cursor.execute(sql, data)
else:
sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
data = (i["name"], 0, 50, 1, i["url"], 0, 1, 0)
cursor.execute(sql, data)
operator.db.commit()
return all
# 拿到新的一级分类的ID
def get_new_allname_and_cat_id():
with operator.db.cursor() as cursor:
sql = "select cat_id,cat_name from lie_category "
cursor.execute(sql)
new = cursor.fetchall()
return new
# 给一级分类添加ID
def add_more_cat_id(all_, new):
for i in all_:
for d in new:
if i['name'] in d:
i['cat_id'] = d[0]
break
return all_
# 给二级分类添加parent_id,生成自己的新ID
def over(all_):
with operator.db.cursor() as cursor:
for a_1 in all_:
for s in a_1['2_list']:
if s.get('cat_id'):
sql = 'UPDATE lie_category SET parent_id=%s,is_show=%s, url=%s,islast=%s,level=%s WHERE cat_id=%s'
data = (a_1['cat_id'], 1, s['url'], 1, 2, s['cat_id'])
cursor.execute(sql, data)
else:
sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
data = (s["name"], a_1['cat_id'], 50, 1, s["url"], 1, 2, 0)
cursor.execute(sql, data)
operator.db.commit()
if __name__ == '__main__':
clean_db()
old = get_old_allname_and_cat_id()
all = get_szlc_all()
all_ = add_cat_id(all, old)
new = get_new_allname_and_cat_id()
all_ = add_more_cat_id(all_, new)
over(all_)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import time
import pymysql
def get_env():
if sys.platform in ('darwin', 'win32'):
return 'test'
else:
return 'produce'
ENV = get_env()
HOST_SET = {
'test': '192.168.1.232',
'produce': '172.18.137.37'
}
UP_SET = {
'test': ('ichunt', 'ichunt'),
'produce': ('bigdata', 'bdYm2yy2mmyzlmlly')
}
def get_mysql_conf(db):
host = HOST_SET[ENV]
up = UP_SET[ENV]
conf = {
'host': host,
'port': 3306,
'user': up[0],
'password': up[1],
'db': db,
'charset': 'utf8'
}
return conf
class MySqlOperator(object):
def __init__(self, db_key_name):
config = get_mysql_conf(db_key_name)
self.db = pymysql.connect(**config)
def re_connect(self):
try:
self.db.ping()
except Exception:
self.db.connect()
@staticmethod
def get_ts():
return int(time.time())
def get_hot_kw(self, kid, condition):
with self.db.cursor() as cursor:
sql = "SELECT id, keyword FROM lie_keywords_hot WHERE search_count {} AND id > %s ORDER BY id LIMIT 1000". \
format(condition)
cursor.execute(sql, kid)
result = cursor.fetchall()
return result
def check_kw_exist(self, kw):
with self.db.cursor() as cursor:
sql = 'SELECT 1 FROM lie_keywords_hot WHERE keyword=%s LIMIT 1'
cursor.execute(sql, kw)
result = cursor.fetchone()
return result
def update_kw_count(self, kw):
with self.db.cursor() as cursor:
sql = "UPDATE lie_keywords_hot SET search_count=search_count + 1 WHERE keyword=%s"
cursor.execute(sql, kw)
self.db.commit()
def insert_kw(self, kw):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_keywords_hot(keyword, search_count) VALUES (%s, 1)
"""
cursor.execute(sql, kw)
self.db.commit()
def get_no_bin(self, gid):
with self.db.cursor() as cursor:
sql = """SELECT DISTINCT(productId), id FROM lie_szlc_order_goods WHERE id >%s AND brand_id=0 ORDER BY id
LIMIT 100"""
cursor.execute(sql, gid)
result = cursor.fetchall()
return result
def get_no_pm(self):
with self.db.cursor() as cursor:
sql = "SELECT productId FROM lie_szlc_order_goods WHERE productModel = '' GROUP BY productId"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_gn_by_gid(self, gid):
with self.db.cursor() as cursor:
sql = "SELECT goods_name FROM szlc.lie_goods WHERE product_id=%s"
cursor.execute(sql, gid)
result = cursor.fetchone()
return result
def update_pm(self, pm, pid):
with self.db.cursor() as cursor:
sql = "UPDATE lie_szlc_order_goods SET productModel=%s WHERE productId=%s"
cursor.execute(sql, (pm, pid))
self.db.commit()
def get_no_bin_count(self):
with self.db.cursor() as cursor:
sql = """SELECT count(DISTINCT(productId)) FROM lie_szlc_order_goods WHERE brand_id=0"""
cursor.execute(sql)
result = cursor.fetchall()
return result
def update_bin(self, data):
with self.db.cursor() as cursor:
sql = "UPDATE lie_szlc_order_goods SET brand_id=%s, brand_name=%s WHERE productId=%s"
cursor.execute(sql, data)
self.db.commit()
# szlc
def get_order_goods_id(self, iid):
with self.db.cursor() as cursor:
sql = "SELECT DISTINCT(productId), id FROM lie_szlc_order_goods WHERE id >%s ORDER BY id LIMIT 100"
cursor.execute(sql, iid)
result = cursor.fetchall()
return result
def get_bid_by_pid(self, pid):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT brand_id FROM szlc.lie_goods WHERE product_id = %s"
cursor.execute(sql, pid)
result = cursor.fetchone()
return result
def get_bn_by_bid(self, bid):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT brand_name FROM szlc.lie_brand WHERE brand_id = %s"
cursor.execute(sql, bid)
result = cursor.fetchone()
return result
def check_goods_exist(self, goods_id):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT 1 FROM szlc.lie_goods WHERE product_id = %s"
cursor.execute(sql, goods_id)
result = cursor.fetchone()
return result
def get_order_info_by_order_id(self, oid):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT 1 FROM lie_szlc_order_info WHERE orderID=%s LIMIT 1"
cursor.execute(sql, oid)
result = cursor.fetchone()
return result
def check_stock_exist(self, sid):
with self.db.cursor() as cursor:
sql = 'SELECT 1 FROM lie_szlc_stock_info WHERE stockId=%s LIMIT 1'
cursor.execute(sql, sid)
result = cursor.fetchone()
return result
def insert_lcsz_stock(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_szlc_stock_info(stockId, date, productName, productType, productId, encapsulationModel,
providerMode, ctime) VALUES (%(stockId)s, %(date)s, %(productName)s,%(productType)s,
%(productId)s, %(encapsulationModel)s, %(providerMode)s, %(ctime)s)
"""
cursor.execute(sql, data)
self.db.commit()
def update_lcsz_order_list(self, data):
with self.db.cursor() as cursor:
sql = "UPDATE lie_szlc_order_info SET paymentStatus=%s, orderStatus=%s, mtime=%s WHERE orderID=%s"
cursor.execute(sql, data)
self.db.commit()
# cursor.close()
def insert_lcsz_order_list(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_szlc_order_info(orderID, clientName, clientID, orderTS, totalPrice, paymentStatus,
orderStatus, ctime, mtime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
# ON DUPLICATE KEY UPDATE paymentStatus=VALUES (paymentStatus), orderStatus=VALUES (orderStatus),
# mtime=VALUES (mtime)
cursor.execute(sql, data)
self.db.commit()
# finally:
# cursor.close()
def insert_lcsz_order_details(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_szlc_order_goods(productId, orderID, productName, productType, encapsulationModel,
productModel, splitNumber, productPrice, minBatchPrice, ctime, brand_id, brand_name) VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
cursor.executemany(sql, data)
self.db.commit()
# cursor.close()
def update_img_by_goods_name(self, img, goods_name):
with self.db.cursor() as cursor:
sql = """
UPDATE lie_goods_merge SET goods_img=%s WHERE goods_name=%s
"""
cursor.execute(sql, (img, goods_name))
self.db.commit()
def get_total_page(self):
with self.db.cursor() as cursor:
sql = "SELECT count(goods_id) AS co FROM lie_goods"
cursor.execute(sql)
result = cursor.fetchone()
if not result[0]:
return
total_pages = result[0] // 100
if total_pages % 100 != 0:
total_pages += 1
return total_pages
def get_first_goods_id(self):
with self.db.cursor() as cursor:
sql = "SELECT goods_id FROM lie_goods ORDER BY goods_id LIMIT 1"
cursor.execute(sql)
result = cursor.fetchone()
return result[0]
def get_total(self):
with self.db.cursor() as cursor:
sql = "SELECT count(goods_id) FROM lie_goods"
cursor.execute(sql)
result = cursor.fetchone()
return result[0]
def get_goods_info_arrow(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
# sql = "SELECT cat_id, url,ext_fields FROM lie_category WHERE islast=1 LIMIT %s, 100" % start
sql = """
SELECT a.goods_id, a.goods_name, a.goods_sn, a.site_url, a.provider_name, a.pdf_url, b.url referer FROM
lie_goods AS a
INNER JOIN lie_category AS b ON a.cat_id = b.cat_id WHERE a.goods_id > %s ORDER BY a.goods_id
LIMIT 100"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
def get_goods_info_rs(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = """
SELECT cat_id, goods_id, goods_name, goods_sn, site_url,
provider_name,goods_desc FROM lie_goods
WHERE goods_id > %s ORDER BY goods_id ASC
LIMIT 200"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
def get_goods_info_master(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = """
SELECT goods_id, goods_name, goods_sn, site_url, provider_name
FROM lie_goods
WHERE goods_id > %s ORDER BY goods_id ASC
LIMIT 50"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
def get_goods_info_verical(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = """SELECT goods_id, goods_name, goods_sn, pdf_url, goods_brief,
provider_name FROM lie_goods WHERE goods_id >%s ORDER BY goods_id LIMIT 100"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
# common
def get_cate_count(self):
with self.db.cursor() as cursor:
sql = "SELECT count(*) as co FROM lie_category WHERE parent_id !=0"
cursor.execute(sql)
result = cursor.fetchone()
return result[0]
def get_cate_by_page(self, page):
start = str((page - 1) * 100)
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url FROM lie_category WHERE parent_id != 0 LIMIT %s, 100" % start
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_by_page_avnet(self, page):
start = str((page - 1) * 100)
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url,ext_fields FROM lie_category WHERE islast=1 LIMIT %s, 100" % start
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_by_page_arrow(self, page):
start = str((page - 1) * 100)
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url, cat_name FROM lie_category where islast=1 AND is_show=1 LIMIT %s, 100" % start
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_verical(self):
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url FROM lie_category WHERE islast=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_allied(self):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = "SELECT cat_id, url, cat_name FROM lie_category WHERE islast=1 AND is_show=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_master(self):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = "SELECT cat_id, url, page_count FROM lie_category WHERE islast=1 AND is_show=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_powell(self):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = "SELECT cat_id, url FROM lie_category WHERE islast=1 AND is_show=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def update_cate_status(self, cat_id):
with self.db.cursor() as cursor:
sql = """
UPDATE lie_category SET is_show = 0 WHERE cat_id = %s
"""
cursor.execute(sql, cat_id)
self.db.commit()
def get_cat_id_by_name(self, name):
with self.db.cursor() as cursor:
sql = "SELECT cat_id FROM lie_category WHERE cat_name=%s"
cursor.execute(sql, name)
result = cursor.fetchone()
result = result[0] if result else None
return result
def insert_cate(self, cate):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_category(cat_name, keywords, parent_id, url, islast, level, ext_fields) VALUES (%s, %s,
%s, %s, %s, %s, %s)
"""
cursor.execute(sql, cate)
self.db.commit()
def insert_cate_2(self, cate):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_category(cat_name, keywords, parent_id, url, islast, level, ext_fields) VALUES (%s, %s,
%s, %s, %s, %s, %s)
"""
cursor.execute(sql, cate)
self.db.commit()
def insert_cate_3(self, cate):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_category(cat_name, keywords, parent_id, url, islast, level, supplier_id) VALUES (%s, %s,
%s, %s, %s, %s, %s)
"""
cursor.execute(sql, cate)
self.db.commit()
def update_cate(self, cate_name, page):
with self.db.cursor() as cursor:
sql = """
UPDATE lie_category SET page_count = %s WHERE cat_name = %s
"""
cursor.execute(sql, (page, cate_name))
self.db.commit()
def get_parent_id(self, name):
with self.db.cursor() as cursor:
sql = "SELECT cat_id FROM lie_category WHERE cat_name = %s"
cursor.execute(sql, name)
result = cursor.fetchone()
result = result[0] if result else None
return result
def get_goods_id_by_goods_sn(self, gs):
with self.db.cursor() as cursor:
sql = "SELECT goods_id FROM lie_goods WHERE goods_sn=%s"
cursor.execute(sql, gs)
result = cursor.fetchone()
result = result[0] if result else None
return result
def get_brand_id_by_brand_name(self, bn):
with self.db.cursor() as cursor:
sql = "SELECT brand_id FROM lie_brand WHERE brand_name=%s"
cursor.execute(sql, (bn,))
result = cursor.fetchone()
result = result[0] if result else 0
return result
def add_goods(self, goods):
with self.db.cursor() as cursor:
goods['add_time'] = self.get_ts()
sql = """
INSERT INTO lie_goods(cat_id, goods_sn, goods_name, goods_name_style, provider_name, brand_id,
goods_number, min_buynum, goods_brief, goods_desc, goods_thumb, goods_img, site_url, pdf_url,
add_time) VALUES
(%(cat_id)s, %(goods_sn)s, %(goods_name)s, %(goods_name_style)s, %(provider_name)s, %(brand_id)s,
%(goods_number)s, %(min_buynum)s, %(goods_brief)s, %(goods_desc)s, %(goods_thumb)s, %(goods_img)s,
%(site_url)s, %(pdf_url)s, %(add_time)s)
"""
cursor.execute(sql, goods)
self.db.commit()
def add_goods_company(self, goods):
with self.db.cursor() as cursor:
goods['add_time'] = self.get_ts()
sql = """
INSERT INTO lie_goods(cat_id, goods_sn, goods_name, goods_name_style, provider_name, brand_id,
goods_number, min_buynum, goods_brief, goods_desc, goods_thumb, goods_img, site_url, pdf_url,
add_time, supplier_id, canal) VALUES
(%(cat_id)s, %(goods_sn)s, %(goods_name)s, %(goods_name_style)s, %(provider_name)s, %(brand_id)s,
%(goods_number)s, %(min_buynum)s, %(goods_brief)s, %(goods_desc)s, %(goods_thumb)s, %(goods_img)s,
%(site_url)s, %(pdf_url)s, %(add_time)s, %(supplier_id)s, %(canal)s)
"""
cursor.execute(sql, goods)
self.db.commit()
def add_brand(self, brand):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_brand(brand_name, site_url, brand_desc) VALUES (%(brand_name)s, %(site_url)s,
%(brand_desc)s)
"""
cursor.execute(sql, brand)
self.db.commit()
def check_price_exist(self, goods_id):
with self.db.cursor() as cursor:
n = str(goods_id)[-1]
sql = "SELECT COUNT(*) FROM lie_goods_price_{} WHERE goods_id=%s".format(n)
cursor.execute(sql, goods_id)
result = cursor.fetchone()
return result[0]
def add_price(self, prices):
with self.db.cursor() as cursor:
n = str(prices['goods_id'])[-1]
sql = "INSERT INTO lie_goods_price_{0}(goods_id, price) VALUES (%(goods_id)s, %(price)s)".format(n)
cursor.execute(sql, prices)
self.db.commit()
def get_attr_id_by_name(self, cate_attr): # (id, name)
with self.db.cursor() as cursor:
sql = "SELECT attr_id FROM lie_category_attr WHERE cat_id=%s AND attr_name=%s"
cursor.execute(sql, cate_attr)
result = cursor.fetchone()
result = result[0] if result else None
return result
def add_cate_attr(self, cate_attr):
with self.db.cursor() as cursor:
sql = "INSERT INTO lie_category_attr(cat_id, attr_name) VALUES (%s, %s)"
cursor.execute(sql, cate_attr)
self.db.commit()
def get_ext_id_by_goods_id_attr_name(self, gi, an):
with self.db.cursor() as cursor:
n = str(gi)[-1]
sql = "SELECT ext_id FROM lie_goods_attr_fields{0} WHERE goods_id=%s AND attr_name=%s".format(n)
cursor.execute(sql, (gi, an))
result = cursor.fetchone()
result = result[0] if result else None
return result
def add_attr(self, ext_data):
with self.db.cursor() as cursor:
n = str(ext_data['goods_id'])[-1]
sql = """
INSERT INTO lie_goods_attr_fields{0}(goods_id, cat_id, attr_id, attr_name, attr_value)VALUES
(%(goods_id)s, %(cat_id)s, %(attr_id)s, %(attr_name)s, %(attr_value)s)""".format(n)
cursor.execute(sql, ext_data)
self.db.commit()
def get_not_img(self, platform, goods_id):
with self.db.cursor() as cursor:
sql = """SELECT id, goods_name FROM lie_goods_merge WHERE goods_img = '' AND supplier_name = %s AND id
> %s ORDER BY id LIMIT 500
"""
cursor.execute(sql, (platform, goods_id))
result = cursor.fetchall()
return result
def update_brand(self, gid, brand):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET provider_name=%s WHERE goods_id=%s"
cursor.execute(sql, (brand, gid))
self.db.commit()
def update_brands(self, gid, brand, brand_id):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET provider_name=%s, brand_id=%s WHERE goods_id=%s"
cursor.execute(sql, (brand, brand_id, gid))
self.db.commit()
def update_status(self, gid, is_delete=1):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET is_delete=%s WHERE goods_id=%s"
cursor.execute(sql, (is_delete, gid))
self.db.commit()
def update_cost(self, gid, cost):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET has_cost=%s WHERE goods_id=%s"
cursor.execute(sql, (cost, gid))
self.db.commit()
# pc
def insert_pc(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_price_relations(goods_id, goods_name, goods_sn, provider_name, add_time, prices,
prices_ori, avg_disparity_usd, avg_disparity_rmb, platform, compare) VALUES
(%(goods_id)s, %(goods_name)s, %(goods_sn)s, %(provider_name)s, %(batch_time)s, %(prices)s,
%(prices_ori)s, %(avg_disparity_usd)s, %(avg_disparity_rmb)s, %(pn)s, %(cp)s)
"""
cursor.execute(sql, data)
self.db.commit()
# element
def update_url(self, gid, url):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET site_url=%s WHERE goods_id=%s"
cursor.execute(sql, (url, gid))
self.db.commit()
# truncate
def truncate_cate(self):
with self.db.cursor() as cursor:
sql = "TRUNCATE lie_category"
cursor.execute(sql)
self.db.commit()
if __name__ == '__main__':
# pass
d = MySqlOperator('szlc')
# print(d.get_ext_id_by_goods_id_attr_name(18000500790, 'Product Category'))
# data = (('SO180219037', '蔡**', '19**62A', 1519055525, '2018-02-19 23:52:05', 100, '已付3', '好好', '待取货3', 1519055525,
# 2519055525),
# ('SO180219035', '蔡**', '19**62A', 1519055525, '2018-02-19 23:52:05', 100, '衣付3', '好好', '待取货3', 1519055525,
# 2519055525))
# d.insert_lcsz_order_list(data)
# data1 = (
# ('SO180219034_3', 'SO180219037', '91383', '4.7nH ±0.3nH 编带', '高频电感', '0402', 500, 0.019, 0.0118, 1519055525),
# ('SO180219034_4', 'SO180219037', '91383', '4.7nH ±0.3nH 编带', '高频电感', '0402', 500, 0.019, 0.0118, 1519055525),
# )
# d.insert_lcsz_order_details(data1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment