import pymysql
from pandas import DataFrame
import numpy as np
import pandas as pd
def findFromViogiData(ebaynos):
db = pymysql.connect(host='****', user='**', passwd='**', db='*', port=3306, charset='utf8')
cursor = db.cursor()
# ebaynos =[ '152329556836', '121698891442', '161719488555', '130982977280', '121801322206']
arrs = ', '.join(list(map(lambda x: '%s', ebaynos)))
sql = ' select p.ebayno, p.category FROM product p where p.ebayno in (%s)'%(arrs)
cursor.execute(sql,ebaynos)
data = cursor.fetchall()#元祖中的元素也是元祖
if len(data) == 0:
print("viogidata搜索结果为空")
return
data = np.array(data) #将元祖转换成数组
df = DataFrame(data , columns=["ebayno","category"])#创建对象DataFrame,参数值为数组
df.to_csv("category_viogidata.csv" , index=False) #输出
db.commit()
cursor.close()
db.close()
def findFromViogiDataer(ebaynos):
db = pymysql.connect(host='**', user='**', passwd='**', db='*', port=3306, charset='utf8')
cursor = db.cursor()
# ebaynos =[ '152329556836', '121698891442', '161719488555', '130982977280', '121801322206']
arrs = ', '.join(list(map(lambda x: '%s', ebaynos)))
sql = ' select p.ebayno, p.category FROM product p where p.ebayno in (%s)'%(arrs)
cursor.execute(sql,ebaynos)
data = cursor.fetchall()#元祖中的元素也是元祖
if len(data) == 0:
print("viogidataer搜索结果为空")
return
data = np.array(data) #将元祖转换成数组
df = DataFrame(data , columns=["ebayno","category"])#创建对象DataFrame,参数值为数组
df.to_csv("category_viogidataer.csv" , index=False) #输出
db.commit()
cursor.close()
db.close()
ebaynos = [] #读入ebaynos
with open("test1.txt") as fp:
for line in fp:
ebaynos.append(line.strip())
findFromViogiData(ebaynos) #从viogidata读取数据,并放入category_viogidata.csv
findFromViogiDataer(ebaynos) #从viogidataer读取数据,并放入category_viogidataer.csv