Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-opsdoc
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a70c9250
authored
Oct 22, 2024
by
chenxi
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
提交python脚本
1 parent
3dfeb115
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
1.75.0/update_sys_order_pic.py
1.75.0/update_sys_order_pic.py
0 → 100644
View file @
a70c925
import
hashlib
import
pymysql
import
requests
# 数据库连接配置
db_config
=
{
'host'
:
'192.168.5.1'
,
'port'
:
3307
,
'user'
:
'user_yangll'
,
'password'
:
'vGxw9jWg'
,
'db'
:
'glsx_car_service'
,
'charset'
:
'utf8mb4'
,
'cursorclass'
:
pymysql
.
cursors
.
DictCursor
}
def
main
():
# 建立数据库连接
connection
=
pymysql
.
connect
(
**
db_config
)
try
:
# 创建游标对象
with
connection
.
cursor
()
as
cursor
:
# 查询所有图片路径
sql_select
=
"SELECT id, file_path FROM sys_order_file WHERE file_md5 = ''"
cursor
.
execute
(
sql_select
)
results
=
cursor
.
fetchall
()
# 遍历结果,下载图片并计算MD5
for
row
in
results
:
file_id
=
row
[
'id'
]
file_path
=
row
[
'file_path'
]
try
:
# 获取图片内容
print
(
'file_path:'
+
file_path
)
response
=
requests
.
get
(
file_path
)
response
.
raise_for_status
()
# 确保请求成功
image_content
=
response
.
content
# 计算MD5值
md5_hash
=
hashlib
.
md5
()
md5_hash
.
update
(
image_content
)
file_md5
=
md5_hash
.
hexdigest
()
print
(
'file_md5'
+
file_md5
)
# 更新数据库中的file_md5字段
sql_update
=
"UPDATE sys_order_file SET file_md5 =
%
s WHERE id =
%
s"
cursor
.
execute
(
sql_update
,
(
file_md5
,
file_id
))
except
requests
.
RequestException
as
e
:
print
(
f
"无法获取图片或计算MD5: {file_path}, 错误: {e}"
)
# 提交更改
connection
.
commit
()
finally
:
# 关闭数据库连接
connection
.
close
()
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment