Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
重
重点类信息提取
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ZGC_INDEX
重点类信息提取
Commits
f2096656
Commit
f2096656
authored
May 11, 2021
by
LAPTOP-1TK31LNP\liang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
类别更新通用代码
parent
f0f0dde2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
28 deletions
+61
-28
类别更新导入数据库.py
公共代码/类别更新导入数据库.py
+61
-28
No files found.
公共代码/类别更新导入数据库.py
View file @
f2096656
...
...
@@ -5,31 +5,57 @@ import pymssql
# coding=utf-8
#读取excel中的内容
df
=
pd
.
read_excel
(
'处理后数据-扫描仪数据0407.xlsx'
,
sheet_name
=
2
,
converters
=
{
'产品名称'
:
str
,
'类别名称'
:
str
,
'产品品牌'
:
str
,
'类别编码'
:
str
,
'产品编码'
:
str
}
)
def
clean_excel
(
DATABASE
):
#需要修改为1不用修改为0
index_row
=
0
is_important_category
=
[]
df_test
=
pd
.
read_excel
(
'显示器产品类别分析0428.xlsx'
,
sheet_name
=
0
,
converters
=
{
'产品编码'
:
str
,
'备注'
:
str
,
'是否为重点类'
:
str
})
category_name
=
df_test
[
'类别名称'
]
.
tolist
()
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'zgcprice20200628'
,
database
=
DATABASE
,
autocommit
=
True
)
#创建游标
cursor
=
conn
.
cursor
()
sql
=
(
"SELECT category_name FROM important_category_service"
)
cursor
.
execute
(
sql
)
important_category_tuple
=
cursor
.
fetchone
()
important_category
=
''
.
join
(
important_category_tuple
)
for
i
in
category_name
:
if
str
(
i
)
in
important_category
:
is_important_category
.
append
(
'0'
)
index_row
+=
1
else
:
is_important_category
.
append
(
'1'
)
index_row
+=
1
df_test
[
'是否需要手动修改'
]
=
is_important_category
df_clean
=
df_test
[
df_test
[
'备注'
]
==
'1'
]
df_clean
.
to_excel
(
r'显示器产品类别分析0428_清洗后.xlsx'
,
index
=
False
)
return
df_clean
#SKU命名
def
all_modify_SKU_name
(
product_name
,
category_name
):
def
all_modify_SKU_name
(
product_name
,
category_name
,
product_category
,
DATABASE
):
list_temp
=
[]
#需要输出的列表
index_row
=
0
#从excel中获取两个列的数据,类型为list
product_name_list
=
df
[
product_name
]
.
tolist
()
category_name_list
=
df
[
category_name
]
.
tolist
()
product_name_list
=
df_clean
[
product_name
]
.
tolist
()
category_name_list
=
df_clean
[
category_name
]
.
tolist
()
product_category_list
=
df_clean
[
product_category
]
.
tolist
()
import_category_list
=
df_clean
[
"是否重点类"
]
.
tolist
()
#替换产品名称中错误的类别
for
i
in
product_name_list
:
temp
=
i
.
replace
(
"扫描仪"
,
category_name_list
[
index_row
])
if
(
temp
==
i
):
temp_1
=
i
.
replace
(
"扫描枪"
,
category_name_list
[
index_row
])
list_temp
.
append
(
temp_1
)
else
:
list_temp
.
append
(
temp
)
#判断长度
if
(
index_row
<
len
(
product_name_list
)
-
1
):
index_row
+=
1
#遍历完列表
else
:
print
(
"Through the list"
)
#重点类,需要生成新sku名字
if
import_category_list
[
index_row
]
==
1
:
temp
=
i
.
replace
(
category_name_list
[
index_row
],
""
)
temp_1
=
temp
.
replace
(
product_category_list
[
index_row
],
""
)
temp_final
=
temp_1
+
" "
+
category_name_list
[
index_row
]
list_temp
.
append
(
temp_final
)
#非重点类,sku名字已经修改正确
else
:
list_temp
.
append
(
i
)
print
(
"Through the list"
)
#检查替换后的列表
SKU_name
=
list_temp
print
(
SKU_name
)
return
SKU_name
#SPU命名
...
...
@@ -37,8 +63,8 @@ def all_modify_SPU_name(product_brand,category_name):
list_temp
=
[]
index_row
=
0
#从excel中获取两个列的数据,类型为list
product_brand_list
=
df
[
product_brand
]
.
tolist
()
category_name_list
=
df
[
category_name
]
.
tolist
()
product_brand_list
=
df
_clean
[
product_brand
]
.
tolist
()
category_name_list
=
df
_clean
[
category_name
]
.
tolist
()
#合并两项成为SPU
for
i
in
product_brand_list
:
temp
=
product_brand_list
[
index_row
]
+
' '
+
category_name_list
[
index_row
]
...
...
@@ -55,10 +81,10 @@ def all_match_SPU_name(DATABASE,TEST_DATABASE,SPU_name, CATEGORY_id, BRAND_id):
# password 密码
# database 数据库名称
#连接数据库
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'zgcprice20200628'
,
database
=
TEST_
DATABASE
,
autocommit
=
True
)
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'zgcprice20200628'
,
database
=
DATABASE
,
autocommit
=
True
)
#创建游标
cursor_database
=
conn
.
cursor
()
conn_test
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'zgcprice20200628'
,
database
=
TEST_
DATABASE
,
autocommit
=
True
)
conn_test
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'zgcprice20200628'
,
database
=
DATABASE
,
autocommit
=
True
)
#创建游标
cursor_test
=
conn_test
.
cursor
()
#需要输出的列表
...
...
@@ -109,19 +135,19 @@ def all_match_SPU_name(DATABASE,TEST_DATABASE,SPU_name, CATEGORY_id, BRAND_id):
def
all_get_category_id
(
category_id
):
category_id_list
=
df
[
category_id
]
.
tolist
()
category_id_list
=
df
_clean
[
category_id
]
.
tolist
()
#print(category_id_list)
return
category_id_list
def
all_get_brand_id
(
product_brand
,
DATABASE
):
product_brand_list
=
df
[
product_brand
]
.
tolist
()
product_brand_list
=
df
_clean
[
product_brand
]
.
tolist
()
list_brand_id_update
=
[]
conn
=
pymssql
.
connect
(
host
=
'123.56.115.207'
,
user
=
'zgcprice3311'
,
password
=
'zgcprice20200628'
,
database
=
DATABASE
,
autocommit
=
True
)
#创建游标
cursor_read
=
conn
.
cursor
()
for
i
in
product_brand_list
:
#print(i)
#print(i)
.
sql
=
(
"SELECT id FROM p_brand WHERE name =
%
s"
)
cursor_read
.
execute
(
sql
,
i
)
brand_update_id_tuple
=
cursor_read
.
fetchone
()
...
...
@@ -149,8 +175,8 @@ def delete_data(SPU_name, DATABASE):
def
get_sku
(
sku
):
sku_list
=
df
[
sku
]
.
tolist
()
print
(
sku_list
)
sku_list
=
df
_clean
[
sku
]
.
tolist
()
#
print(sku_list)
return
(
sku_list
)
...
...
@@ -160,14 +186,14 @@ def get_spu_id(spu, DATABASE):
#创建游标
cursor_read
=
conn
.
cursor
()
for
i
in
spu
:
print
(
i
)
#
print(i)
#print(i)
sql
=
(
"SELECT id FROM p_spu WHERE spu =
%
s"
)
cursor_read
.
execute
(
sql
,
i
)
temp
=
cursor_read
.
fetchone
()
spu_id_list
.
append
(
temp
[
0
])
#判断产品ID是否存在
print
(
spu_id_list
)
#
print(spu_id_list)
conn
.
close
()
return
(
spu_id_list
)
...
...
@@ -205,18 +231,25 @@ def update_sku_data(DATABASE,SKU,SKU_name,SPU_ID):
sku
=
'产品编码'
product_brand
=
'产品品牌'
product_name
=
'产品名称'
product_category
=
'产品类别'
category_name
=
'类别名称'
category_id
=
'类别编码'
database
=
'ZI_NEW'
database
=
'ZI_NEW
_TEST
'
test_database
=
'ZI_NEW_TEST'
SKU_name
=
all_modify_SKU_name
(
product_name
,
category_name
)
#在跑之前只需改第243行得excel文件路径和第237行得库名
#df_clean = clean_excel(database)
df_excel
=
pd
.
read_excel
(
'显示器产品类别分析0510.xlsx'
,
sheet_name
=
0
,
converters
=
{
'产品编码'
:
str
})
df_clean
=
df_excel
[
df_excel
[
'备注'
]
==
1
]
SKU_name
=
all_modify_SKU_name
(
product_name
,
category_name
,
product_category
,
database
)
SPU_name
=
all_modify_SPU_name
(
product_brand
,
category_name
)
CATEGORY_id
=
all_get_category_id
(
category_id
)
BRAND_id
=
all_get_brand_id
(
product_brand
,
database
)
SPU
=
all_match_SPU_name
(
database
,
database
,
SPU_name
,
CATEGORY_id
,
BRAND_id
)
SKU
=
get_sku
(
sku
)
SPU_ID
=
get_spu_id
(
SPU
,
database
)
#print(SKU)
update_sku_data
(
database
,
SKU
,
SKU_name
,
SPU_ID
)
#delete_data(SPU_name, test_database)删库内数据用的,少用
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment