Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
my_flask_web
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 3a4822db
authored
Feb 23, 2024
by
周杭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
log日志打印
1 parent
fe907e4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
25 deletions
kafka_consumer/orc_consumer.py
logger.py
kafka_consumer/orc_consumer.py
View file @
3a4822d
...
@@ -24,13 +24,13 @@ environment = sys.argv[1] if len(sys.argv) > 1 else "default"
...
@@ -24,13 +24,13 @@ environment = sys.argv[1] if len(sys.argv) > 1 else "default"
# environment = os.environ.get('ENV')
# environment = os.environ.get('ENV')
if
environment
==
'pro'
:
if
environment
==
'pro'
:
from
config_pro
import
Config
from
config_pro
import
Config
print
(
vars
(
Config
))
log
.
info
(
vars
(
Config
))
elif
environment
==
'test'
:
elif
environment
==
'test'
:
from
config_test
import
Config
from
config_test
import
Config
print
(
vars
(
Config
))
log
.
info
(
vars
(
Config
))
else
:
else
:
from
config_dev
import
Config
from
config_dev
import
Config
print
(
vars
(
Config
))
log
.
info
(
vars
(
Config
))
# 配置 Kafka 消费者
# 配置 Kafka 消费者
conf
=
{
conf
=
{
...
@@ -111,7 +111,7 @@ def get_project_root():
...
@@ -111,7 +111,7 @@ def get_project_root():
current_file
=
os
.
path
.
abspath
(
__file__
)
current_file
=
os
.
path
.
abspath
(
__file__
)
# 获取当前项目的根目录
# 获取当前项目的根目录
project_root
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
current_file
))
project_root
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
current_file
))
print
(
project_root
)
log
.
info
(
project_root
)
return
project_root
return
project_root
...
@@ -238,11 +238,11 @@ def handler_vin(dst, flag, angle, path,row):
...
@@ -238,11 +238,11 @@ def handler_vin(dst, flag, angle, path,row):
# result = ocr.ocr(image_path.replace("train", "validation"), cls=True)
# result = ocr.ocr(image_path.replace("train", "validation"), cls=True)
for
line
in
result
:
for
line
in
result
:
print
(
line
)
log
.
info
(
line
)
#
print
(line[0][1][0])
#
log.info
(line[0][1][0])
result_list
=
flatten_list
(
result
)
result_list
=
flatten_list
(
result
)
print
(
"result_list"
,
result_list
)
log
.
info
(
"result_list"
,
result_list
)
with
open
(
"./log10.txt"
,
"a+"
,
encoding
=
"utf-8"
)
as
file
:
with
open
(
"./log10.txt"
,
"a+"
,
encoding
=
"utf-8"
)
as
file
:
if
result_list
is
not
None
:
if
result_list
is
not
None
:
file
.
write
(
path
+
"----"
+
str
(
result_list
)
+
"
\n
"
)
file
.
write
(
path
+
"----"
+
str
(
result_list
)
+
"
\n
"
)
...
@@ -252,7 +252,7 @@ def handler_vin(dst, flag, angle, path,row):
...
@@ -252,7 +252,7 @@ def handler_vin(dst, flag, angle, path,row):
# 使用正则表达式进行过滤 获取车架号
# 使用正则表达式进行过滤 获取车架号
vin_str
=
""
vin_str
=
""
for
item
in
result_list
:
for
item
in
result_list
:
print
(
item
)
log
.
info
(
item
)
vin_check
=
extract_vin
(
item
)
vin_check
=
extract_vin
(
item
)
if
vin_check
is
not
None
:
if
vin_check
is
not
None
:
vin_str
=
vin_check
vin_str
=
vin_check
...
@@ -260,22 +260,22 @@ def handler_vin(dst, flag, angle, path,row):
...
@@ -260,22 +260,22 @@ def handler_vin(dst, flag, angle, path,row):
break
break
if
vin_str
:
if
vin_str
:
print
(
str
(
row
))
log
.
info
(
str
(
row
))
print
(
vin_str
)
log
.
info
(
vin_str
)
# 定义要执行的SQL语句
# 定义要执行的SQL语句
SQL01
=
f
"""
SQL01
=
f
"""
INSERT INTO sys_order_ocr_vin_result (order_id,file_id,db_vin,ocr_vin,create_time,update_time)
INSERT INTO sys_order_ocr_vin_result (order_id,file_id,db_vin,ocr_vin,create_time,update_time)
VALUES ({row[0]},{row[1]},'{row[3]}','{vin_str}',sysdate(),sysddate())
VALUES ({row[0]},{row[1]},'{row[3]}','{vin_str}',sysdate(),sysddate())
"""
"""
# 执行SQL语句
# 执行SQL语句
print
(
SQL01
)
log
.
info
(
SQL01
)
cursor_dev
.
execute
(
SQL01
)
cursor_dev
.
execute
(
SQL01
)
conn_dev
.
commit
()
conn_dev
.
commit
()
return
flag
return
flag
def
handle_process
(
row
):
def
handle_process
(
row
):
print
(
"Received message handle_process: {}"
,
row
)
log
.
info
(
"Received message handle_process: {}"
,
row
)
order_id
=
row
.
get
(
"orderId"
)
order_id
=
row
.
get
(
"orderId"
)
file_id
=
row
.
get
(
"fileId"
)
file_id
=
row
.
get
(
"fileId"
)
...
@@ -286,17 +286,17 @@ def handle_process(row):
...
@@ -286,17 +286,17 @@ def handle_process(row):
# 删除数据库里的旧数据
# 删除数据库里的旧数据
delete_sql1
=
"DELETE FROM sys_order_ocr_sn_result WHERE order_id = {}"
.
format
(
order_id
)
delete_sql1
=
"DELETE FROM sys_order_ocr_sn_result WHERE order_id = {}"
.
format
(
order_id
)
print
(
delete_sql1
)
log
.
info
(
delete_sql1
)
cursor_dev
.
execute
(
delete_sql1
)
cursor_dev
.
execute
(
delete_sql1
)
conn_dev
.
commit
()
conn_dev
.
commit
()
delete_sql2
=
"DELETE FROM sys_order_ocr_vin_result WHERE order_id = {}"
.
format
(
order_id
)
delete_sql2
=
"DELETE FROM sys_order_ocr_vin_result WHERE order_id = {}"
.
format
(
order_id
)
print
(
delete_sql2
)
log
.
info
(
delete_sql2
)
cursor_dev
.
execute
(
delete_sql2
)
cursor_dev
.
execute
(
delete_sql2
)
conn_dev
.
commit
()
conn_dev
.
commit
()
filename
=
generate_random_filename
()
filename
=
generate_random_filename
()
network_img_path
=
row
.
get
(
"filePath"
)
network_img_path
=
row
.
get
(
"filePath"
)
print
(
"network_img_path"
,
network_img_path
)
log
.
info
(
"network_img_path"
,
network_img_path
)
extension
=
get_extension
(
network_img_path
)
extension
=
get_extension
(
network_img_path
)
complete_filename
=
f
"{filename}.{extension}"
complete_filename
=
f
"{filename}.{extension}"
try
:
try
:
...
@@ -313,14 +313,14 @@ def handle_process(row):
...
@@ -313,14 +313,14 @@ def handle_process(row):
file
.
write
(
response
.
content
)
file
.
write
(
response
.
content
)
# urllib.request.urlretrieve(network_img_path, path)
# urllib.request.urlretrieve(network_img_path, path)
time
.
sleep
(
0.001
)
time
.
sleep
(
0.001
)
print
(
"File downloaded successfully."
)
log
.
info
(
"File downloaded successfully."
)
original_image
=
Image
.
open
(
path
)
original_image
=
Image
.
open
(
path
)
if
original_image
.
mode
==
"RGBA"
:
if
original_image
.
mode
==
"RGBA"
:
original_image
=
original_image
.
convert
(
"RGB"
)
original_image
=
original_image
.
convert
(
"RGB"
)
print
(
original_image
.
mode
)
log
.
info
(
original_image
.
mode
)
# 放大图片
# 放大图片
scale_factor
=
3
# 放大倍数
scale_factor
=
3
# 放大倍数
...
@@ -357,12 +357,12 @@ def handle_process(row):
...
@@ -357,12 +357,12 @@ def handle_process(row):
VALUES ({order_id},{file_id},'{sns}',null,sysdate(),sysddate())
VALUES ({order_id},{file_id},'{sns}',null,sysdate(),sysddate())
"""
"""
# 执行SQL语句
# 执行SQL语句
print
(
SQL02
)
log
.
info
(
SQL02
)
cursor_dev
.
execute
(
SQL02
)
cursor_dev
.
execute
(
SQL02
)
conn_dev
.
commit
()
conn_dev
.
commit
()
print
(
"==========================处理vin=================================="
)
log
.
info
(
"==========================处理vin=================================="
)
# 创建对比度增强器
# 创建对比度增强器
# enhancer = ImageEnhance.Contrast(original_image)
# enhancer = ImageEnhance.Contrast(original_image)
...
@@ -408,17 +408,17 @@ def handle_process(row):
...
@@ -408,17 +408,17 @@ def handle_process(row):
VALUES ({order_id},{file_id},'{vin}',null,sysdate(),sysddate())
VALUES ({order_id},{file_id},'{vin}',null,sysdate(),sysddate())
"""
"""
# 执行SQL语句
# 执行SQL语句
print
(
SQL02
)
log
.
info
(
SQL02
)
cursor_dev
.
execute
(
SQL02
)
cursor_dev
.
execute
(
SQL02
)
conn_dev
.
commit
()
conn_dev
.
commit
()
try
:
try
:
os
.
remove
(
path
)
os
.
remove
(
path
)
print
(
"文件删除成功"
)
log
.
info
(
"文件删除成功"
)
except
FileNotFoundError
:
except
FileNotFoundError
:
print
(
"文件不存在"
)
log
.
info
(
"文件不存在"
)
except
PermissionError
:
except
PermissionError
:
print
(
"权限不足,无法删除文件"
)
log
.
info
(
"权限不足,无法删除文件"
)
# 消费消息并进行逻辑处理
# 消费消息并进行逻辑处理
...
@@ -431,7 +431,7 @@ try:
...
@@ -431,7 +431,7 @@ try:
if
msg
.
error
()
.
code
()
==
KafkaError
.
_PARTITION_EOF
:
if
msg
.
error
()
.
code
()
==
KafkaError
.
_PARTITION_EOF
:
continue
continue
else
:
else
:
print
(
msg
.
error
())
log
.
info
(
msg
.
error
())
break
break
# 处理逻辑
# 处理逻辑
...
...
logger.py
View file @
3a4822d
...
@@ -33,4 +33,4 @@ def setup_logging(log_file):
...
@@ -33,4 +33,4 @@ def setup_logging(log_file):
return
logger
return
logger
log
=
setup_logging
(
'mytest.log'
)
\ No newline at end of file
\ No newline at end of file
log
=
setup_logging
(
'ocr.log'
)
\ 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