Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
d4e9acd6
authored
2020-08-19 15:03:06 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add email sender
1 parent
918035ec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
10 deletions
src/apps/doc/management/commands/doc_ocr_process.py
src/apps/doc/views.py
src/common/tools/mail.py
src/apps/doc/management/commands/doc_ocr_process.py
View file @
d4e9acd
...
...
@@ -6,7 +6,7 @@ import base64
import
asyncio
import
aiohttp
# from openpyxl import Workbook
from
apps.doc.ocr.wb
import
BSWorkbook
from
apps.doc.ocr.wb
import
BSWorkbook
,
Workbook
from
django.core.management
import
BaseCommand
from
settings
import
conf
...
...
@@ -143,6 +143,7 @@ class Command(BaseCommand, LoggerMixin):
continue
sleep_second
=
int
(
conf
.
SLEEP_SECOND
)
# 3.PDF文件提取图片
start_time
=
time
.
time
()
img_save_path
=
os
.
path
.
join
(
doc_data_path
,
'img'
)
self
.
cronjob_log
.
info
(
'{0} [pdf to img start] [business_type={1}] [doc_id={2}]'
.
format
(
self
.
log_base
,
business_type
,
doc
.
id
))
...
...
@@ -156,12 +157,13 @@ class Command(BaseCommand, LoggerMixin):
role_summary
=
{
'银行-户名'
:
[]
}
interest_keyword
=
Keywords
.
objects
.
filter
(
type
=
KeywordsType
.
INTEREST
.
value
)
.
values_list
(
'keyword'
,
flat
=
True
)
salary_keyword
=
Keywords
.
objects
.
filter
(
type
=
KeywordsType
.
SALARY
.
value
)
.
values_list
(
'keyword'
,
flat
=
True
)
loan_keyword
=
Keywords
.
objects
.
filter
(
type
=
KeywordsType
.
LOAN
.
value
)
.
values_list
(
'keyword'
,
flat
=
True
)
wb
=
BSWorkbook
(
interest_keyword
,
salary_keyword
,
loan_keyword
)
# interest_keyword = Keywords.objects.filter(
# type=KeywordsType.INTEREST.value).values_list('keyword', flat=True)
# salary_keyword = Keywords.objects.filter(
# type=KeywordsType.SALARY.value).values_list('keyword', flat=True)
# loan_keyword = Keywords.objects.filter(type=KeywordsType.LOAN.value).values_list('keyword', flat=True)
# wb = BSWorkbook(interest_keyword, salary_keyword, loan_keyword)
wb
=
Workbook
()
loop
=
asyncio
.
get_event_loop
()
tasks
=
[
self
.
img_ocr_excel
(
wb
,
img_path
,
role_summary
)
for
img_path
in
pdf_handler
.
img_path_list
]
loop
.
run_until_complete
(
asyncio
.
wait
(
tasks
))
...
...
@@ -189,7 +191,9 @@ class Command(BaseCommand, LoggerMixin):
else
:
doc
.
status
=
DocStatus
.
COMPLETE
.
value
doc
.
save
()
self
.
cronjob_log
.
info
(
'{0} [doc process complete] [business_type={1}] [doc_id={2}]'
.
format
(
self
.
log_base
,
business_type
,
doc
.
id
))
end_time
=
time
.
time
()
speed_time
=
int
(
end_time
-
start_time
)
self
.
cronjob_log
.
info
(
'{0} [doc process complete] [business_type={1}] [doc_id={2}] '
'[speed_time={3}]'
.
format
(
self
.
log_base
,
business_type
,
doc
.
id
,
speed_time
))
self
.
cronjob_log
.
info
(
'{0} [stop safely]'
.
format
(
self
.
log_base
))
...
...
src/apps/doc/views.py
View file @
d4e9acd
...
...
@@ -253,7 +253,7 @@ class DocView(GenericView, DocHandler):
query
=
application_id_query
&
status_query
&
data_source_query
&
upload_finish_time_query
&
create_time_query
val_tuple
=
(
'id'
,
'application_id'
,
'upload_finish_time'
,
'create_time'
,
'data_source'
,
'status'
)
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
doc_queryset
=
doc_class
.
objects
.
filter
(
query
)
.
values
(
*
val_tuple
)
.
order_by
(
'-
upload_finish
_time'
)
doc_queryset
=
doc_class
.
objects
.
filter
(
query
)
.
values
(
*
val_tuple
)
.
order_by
(
'-
create
_time'
)
doc_list
=
self
.
get_doc_list
(
doc_queryset
,
prefix
)
total
=
len
(
doc_list
)
...
...
src/common/tools/mail.py
0 → 100644
View file @
d4e9acd
import
os
import
smtplib
from
email
import
encoders
from
email.header
import
Header
from
email.mime.base
import
MIMEBase
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
MAIL_SERVER_HOST
=
'smtp.exmail.qq.com'
MAIL_SERVER_PORT
=
25
TIME_OUT
=
50
class
MailSender
:
def
__init__
(
self
,
sender
,
pwd
):
self
.
sender
=
sender
self
.
pwd
=
pwd
self
.
server
=
smtplib
.
SMTP
(
timeout
=
TIME_OUT
)
self
.
server
.
debuglevel
=
0
self
.
server
.
connect
(
host
=
MAIL_SERVER_HOST
,
port
=
MAIL_SERVER_PORT
,)
self
.
server
.
login
(
self
.
sender
,
self
.
pwd
)
def
close
(
self
):
self
.
server
.
close
()
def
send
(
self
,
to_addrs
,
subject
,
content
,
file_list
=
[]):
msg
=
MIMEMultipart
()
for
att_file
in
file_list
:
att
=
MIMEBase
(
'application'
,
'octet-stream'
)
att
.
set_payload
(
open
(
att_file
,
'rb'
)
.
read
())
encoders
.
encode_base64
(
att
)
att
.
add_header
(
'Content-Disposition'
,
'attachment'
,
filename
=
Header
(
os
.
path
.
basename
(
att_file
),
'utf-8'
)
.
encode
())
msg
.
attach
(
att
)
msg
[
'Subject'
]
=
Header
(
subject
,
'utf-8'
)
msg
[
'From'
]
=
self
.
sender
msg
[
'To'
]
=
','
.
join
(
to_addrs
)
content
=
u'Hi:<br><br>'
+
\
content
+
\
u'<br><br>祝好!<br><br><br>本邮件为系统自动发送,请勿直接回复!<hr>'
msg
.
attach
(
MIMEText
(
content
.
encode
(
'utf-8'
),
'html'
,
'utf-8'
))
self
.
server
.
sendmail
(
self
.
sender
,
to_addrs
,
msg
.
as_string
())
# smtplib.SMTPServerDisconnected
# if __name__ == '__main__':
# mail_sender = MailSender()
# mail_sender.send(['1304057458@qq.com'], 'hello', 'world.', [])
# mail_sender.close()
Write
Preview
Styling with
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