Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
jd_data_process
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0be98dd6
authored
Oct 18, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add attr
parent
df2ecaaa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
2 deletions
test5.py
test5.py
View file @
0be98dd6
...
...
@@ -184,9 +184,61 @@ def insert_pop_attr_to_db():
print
(
insert_sql
%
(
class_id
,
attr_id
,
attr_name
,
unit
,
enum_value
,
input_type
,
is_required
,
status
,
platform
,
create_time
))
# 单独处理
def
handle_pop_unit
():
select_sql
=
"select id, attr_name from lie_shop_attr where platform = 3 and input_type != 10"
config
=
config_dev
db
=
pymysql
.
connect
(
host
=
config
[
"mysql"
][
"host"
],
port
=
config
[
"mysql"
][
"port"
],
user
=
config
[
"mysql"
][
"user"
],
database
=
config
[
"mysql"
][
"database"
],
password
=
config
[
"mysql"
][
"password"
])
cursor
=
db
.
cursor
()
cursor
.
execute
(
query
=
select_sql
)
db_result
=
cursor
.
fetchall
()
for
i
in
range
(
len
(
db_result
)):
id
=
db_result
[
i
][
0
]
attr_name
=
db_result
[
i
][
1
]
unit
=
process_unit_str
(
attr_name
)
if
unit
==
""
:
continue
default_unit
=
unit
update_sql
=
"update lie_shop_attr set unit =
%
s, default_unit =
%
s where id =
%
s"
cursor
.
execute
(
query
=
update_sql
,
args
=
(
unit
,
default_unit
,
id
,))
db
.
commit
()
print
(
update_sql
%
(
unit
,
default_unit
,
id
))
print
(
"==========================>"
)
select_sql
=
"select id, unit from lie_shop_attr where platform = 3 and input_type = 10"
cursor
.
execute
(
query
=
select_sql
)
db_result
=
cursor
.
fetchall
()
for
i
in
range
(
len
(
db_result
)):
id
=
db_result
[
i
][
0
]
unit
=
db_result
[
i
][
1
]
unit_arr
=
str
(
unit
)
.
split
(
","
)
length
=
len
(
unit_arr
[
0
])
default_unit
=
unit_arr
[
0
][
2
:
length
-
1
]
update_sql
=
"update lie_shop_attr set default_unit =
%
s where id =
%
s"
cursor
.
execute
(
query
=
update_sql
,
args
=
(
default_unit
,
id
,))
db
.
commit
()
print
(
update_sql
%
(
default_unit
,
id
))
def
process_unit_str
(
attr_name
:
str
)
->
str
:
start
=
attr_name
.
find
(
"("
)
end
=
attr_name
.
rfind
(
")"
)
if
start
==
-
1
or
end
==
-
1
or
start
>=
end
or
start
==
0
:
print
(
attr_name
+
" can't match"
)
return
""
else
:
name_str
=
attr_name
[:
start
]
unit_str
=
attr_name
[
start
+
1
:
end
]
if
name_str
==
""
or
unit_str
==
""
:
print
(
attr_name
+
" can't match"
)
return
""
print
(
attr_name
+
" : "
+
unit_str
)
return
unit_str
if
__name__
==
'__main__'
:
pass
\ No newline at end of file
handle_pop_unit
()
\ No newline at end of file
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