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
dd512564
authored
2020-11-07 16:05:44 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
pdf file check
1 parent
e80661aa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
9 deletions
src/apps/doc/consts.py
src/apps/doc/views.py
src/common/tools/mssql_script.py
src/apps/doc/consts.py
View file @
dd51256
import
copy
TIME_NUM
=
600000000
PAGE_DEFAULT
=
1
PAGE_SIZE_DEFAULT
=
10
...
...
src/apps/doc/views.py
View file @
dd51256
...
...
@@ -2,6 +2,7 @@ import os
import
time
import
random
import
datetime
import
fitz
from
django.utils
import
timezone
from
django.db.utils
import
IntegrityError
from
django.db.models
import
Q
...
...
@@ -273,8 +274,17 @@ class DocView(GenericView, DocHandler):
# 上传pdf,模拟下单
@use_args
(
upload_pdf_args
,
location
=
'files'
)
def
post
(
self
,
request
,
args
):
random_int
=
random
.
randint
(
0
,
consts
.
TIME_NUM
)
metadata_version_id
=
str
(
int
(
time
.
time
())
-
random_int
)
# tmp_save_path = os.path.join(conf.DATA_DIR, '{0}.pdf'.format(metadata_version_id))
pdf_file
=
args
.
get
(
'pdf_file'
)
# file_write(pdf_file, tmp_save_path)
if
not
fitz
.
open
(
"pdf"
,
pdf_file
)
.
isPDF
:
raise
self
.
invalid_params
(
msg
=
'invalid params: not a PDF file'
)
# 1. 上传信息记录
metadata_version_id
=
str
(
int
(
time
.
time
()))
application_id
=
'{0}{1}'
.
format
(
consts
.
FIXED_APPLICATION_ID_PREFIX
,
metadata_version_id
)
upload_finish_time
=
timezone
.
now
()
document_scheme
=
random
.
choice
(
consts
.
DOC_SCHEME_LIST
)
...
...
@@ -308,17 +318,18 @@ class DocView(GenericView, DocHandler):
data_source
=
data_source
,
upload_finish_time
=
upload_finish_time
,
)
# 3. 选择队列进入
is_priority
=
False
tasks
=
[
'{0}{1}{2}'
.
format
(
prefix
,
consts
.
SPLIT_STR
,
doc
.
id
)]
enqueue_res
=
rh
.
enqueue
(
tasks
,
is_priority
)
pdf_file
=
args
.
get
(
'pdf_file'
)
# 3.pdf文件移动
save_dir_path
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
business_type
,
str
(
doc
.
id
))
save_file_path
=
os
.
path
.
join
(
save_dir_path
,
'{0}.pdf'
.
format
(
doc
.
id
))
os
.
makedirs
(
save_dir_path
,
exist_ok
=
True
)
file_write
(
pdf_file
,
save_file_path
)
# 4. 选择队列进入
is_priority
=
False
tasks
=
[
'{0}{1}{2}'
.
format
(
prefix
,
consts
.
SPLIT_STR
,
doc
.
id
)]
enqueue_res
=
rh
.
enqueue
(
tasks
,
is_priority
)
self
.
running_log
.
info
(
'[mock doc upload success] [args={0}] [business_type={1}] [doc_id={2}] '
'[is_priority={3}] [enqueue_res={4}]'
.
format
(
args
,
prefix
,
doc
.
id
,
is_priority
,
enqueue_res
))
...
...
src/common/tools/mssql_script.py
View file @
dd51256
import
pyodbc
cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};
SERVER=localhost;UID=SA;PWD=pwd
'
,
autocommit
=
True
)
cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
cursor
=
cnxn
.
cursor
()
cursor
.
execute
(
"create database afc"
)
...
...
@@ -455,7 +455,7 @@ afc_sql = """
on afc_doc (start_time, end_time);
"""
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};
SERVER=localhost;DATABASE=hil;UID=SA;PWD=pwd
'
,
autocommit
=
True
)
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
hil_cursor
=
hil_cnxn
.
cursor
()
hil_cursor
.
execute
(
hil_sql_1
)
...
...
@@ -464,7 +464,7 @@ hil_cursor.execute(hil_sql_2)
hil_cursor
.
close
()
hil_cnxn
.
close
()
afc_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};
SERVER=localhost;DATABASE=afc;UID=SA;PWD=pwd
'
,
autocommit
=
True
)
afc_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
afc_cursor
=
afc_cnxn
.
cursor
()
afc_cursor
.
execute
(
afc_sql
)
...
...
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