Skip to content

Commit

Permalink
slove mulit file
Browse files Browse the repository at this point in the history
  • Loading branch information
ider-zh committed Jul 10, 2018
1 parent ccd3c86 commit 526ec99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions pdf2htmlEX
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def remote_convert(src, argv):
break
else:
raise Exception('remote api is not available! %s'%req.text)

fp = tempfile.TemporaryFile()
fp.write(req.content)
fp.seek(0)
Expand Down
14 changes: 8 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ def upload_file():

if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file_uuid = str(uuid.uuid4())
file_path = os.path.join(app.config['UPLOAD_FOLDER'], file_uuid+'.pdf')
file.save(file_path)
try:
fp = pdf2htmlEX(file_path, json.loads(command))
fp = pdf2htmlEX(file_path, json.loads(command), file_uuid)
except Exception as e:
return str(e),500
app.config['COUNT'] += 1
Expand All @@ -53,8 +54,8 @@ def upload_file():
return "unknow error", 500


def pdf2htmlEX(pdf_path,command):
folder_path = os.path.join(app.config['UPLOAD_FOLDER'], str(uuid.uuid4()))
def pdf2htmlEX(pdf_path,command,file_uuid):
folder_path = os.path.join(app.config['UPLOAD_FOLDER'], file_uuid)
os.mkdir(folder_path)
cmd = [bin,]
if command:
Expand All @@ -64,9 +65,10 @@ def pdf2htmlEX(pdf_path,command):


if os.path.getsize(pdf_path) > 1:
app.config['executor_large'].submit(subprocess.check_output, cmd)
ret = app.config['executor_large'].submit(subprocess.check_output, cmd)
else:
app.config['executor_small'].submit(subprocess.check_output, cmd)
ret = app.config['executor_small'].submit(subprocess.check_output, cmd)
ret.result()

# subprocess.check_output(cmd)
# shutil.copy(pdf_path,os.path.join(pdf_path,folder_path))
Expand Down

0 comments on commit 526ec99

Please sign in to comment.