python实现zencart产品数据导入到magento[python导入数

来源:未知 浏览 133次 时间 2021-06-10 22:28

python版本要求在3.3.x需要mysql connector for python第三方库支持

不适用所有的zencart导入到magento

python实现zencart产品数据导入到magento[python导入数

#连接到zencart数据库
try:
cnn=mysql.connector.connect(**config)

except mysql.connector.Error as e:
print(‘connect fails!{}’.format(e))

python实现zencart产品数据导入到magento[python导入数

try:
cnn_magento=mysql.connector.connect(**config1)

except mysql.connector.Error as e:
print(‘connect fails!{}’.format(e))


#连接到magento数据库

try:
cnn_magento1=mysql.connector.connect(**config1)

except mysql.connector.Error as e:
print(‘connect fails!{}’.format(e))

#————–获取产品信息函数块开始—————#
#(获取产品描述百度优化大师列表类型
products=[]

#连接到zencart数据库
try:
cnn=mysql.connector.connect(**config)

except mysql.connector.Error as e:
print(‘connect fails!{}’.format(e))


#连接到magento数据库

try:
cnn_magento=mysql.connector.connect(**config1)

except mysql.connector.Error as e:
print(‘connect fails!{}’.format(e))


#连接到magento数据库

try:
cnn_magento1=mysql.connector.connect(**config1)

except mysql.connector.Error as e:
print(‘connect fails!{}’.format(e))

#————–获取产品信息函数块开始—————#
#(获取产品描述返回字典)
def get_productdescription(product_id):
global cnn
product_id=str(product_id)
description={}
cursor_des=cnn.cursor()

cursor_des.execute(“select products_name,products_url from products_description where products_id=”+product_id)
temp_description=cursor_des.fetchone()
description[‘name’]=temp_description[0]
description[‘url’]=temp_description[1]

return description

#(获取产品多图返回列表)
def get_productaddtionimage(product_image):

base_dir=”D:\\wamp\www\\public\\images\\”#此处改为自己实际路径
addtion_image=[]
image_uri=(base_dir+product_image).replace(‘.jpg’,”)
for i in range(16):
if os.path.isfile(image_uri+’_’+str(i)+’.jpg’):
addtion_image.append(product_image.replace(‘.jpg’,”)+’_’+str(i)+’.jpg’)


else:
#print (“none”)
pass
return addtion_image

#(获取产品对应目录,返回列表)
def get_product_categories(product_id):

product_id=str(product_id)

categories=[]
cursor=cnn.cursor()

cursor.execute(“select categories_id from products_to_categories where products_id=”+product_id)

for row in cursor.fetchall():

for r in row:
categories.append(r)

return categories

#————–获取产品信息函数块结束—————#

#分类id对应字典
categories_to={\
‘2’:’10’,’3′:’13’,’4′:’18’,’139′:’37’,’176′:’38’,’201′:’70’,’202′:’71’,’203′:’69’,’204′:’76’,’205′:’77’,\
‘206’:’66’,’207′:’73’,’208′:’72’,’209′:’78’,’210′:’79’,’211′:’68’,’212′:’74’,’213′:’59’,’214′:’60’,’215′:’58’,’216′:’62’,’217′:’63’,’218′:’64’,’219′:’65’,’222′:’54’,\
‘223’:’53’,’224′:’56’,’225′:’80’,’230′:’81’,’231′:’48’,’232′:’49’,’233′:’50’,’234′:’82’,’235′:’83’,’236′:’84’,’237′:’45’,’238′:’46’,\
‘239’:’85’,’240′:’51’,’241′:’52’,’242′:’86’,’245′:’40’,’247′:’44’,’248′:’87’,’249′:’43’,’250′:’88’,’251′:’89’,’252′:’42’,\
‘260’:’38’,’261′:’38’,’271′:’41’,\
‘279’:’90’,’280′:’39’,’281′:’61’,’282′:’91’\
}

标签: descriptionidimageproduct