1.修改上传文件的类型
This commit is contained in:
parent
b4a256c3a6
commit
2b4555e1bc
@ -26,7 +26,7 @@ from db import get_database
|
|||||||
from db.ckdb import get_ck_db, CKDrive
|
from db.ckdb import get_ck_db, CKDrive
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from models.interview_zsgc import InterviewDo
|
from models.interview_zsgc import InterviewDo
|
||||||
from utils import get_time, qujian_time, Download_xlsx, send_str_mail
|
from utils import get_time, qujian_time, Download_xlsx, send_str_mail, doc2pdf
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -281,8 +281,12 @@ async def file_to_hw(
|
|||||||
return schemas.Msg(code=400, msg='上传文件有误', data=None)
|
return schemas.Msg(code=400, msg='上传文件有误', data=None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
fn = path_data + '/' + filename
|
||||||
|
if fn.endswith('pdf'): # pdf正常上传到华为云
|
||||||
res = obsClient.putFile('legu-cdn-source', 'hrms/' + filename, path_data + '/' + filename)
|
res = obsClient.putFile('legu-cdn-source', 'hrms/' + filename, path_data + '/' + filename)
|
||||||
|
else: # doc/docx则转化为pdf上传到华为云
|
||||||
|
new_fn,fil = doc2pdf(fn, path_data, filename)
|
||||||
|
res = obsClient.putFile('legu-cdn-source', 'hrms/' + fil, new_fn)
|
||||||
if res.status < 300:
|
if res.status < 300:
|
||||||
# 地址
|
# 地址
|
||||||
url = res.body.objectUrl
|
url = res.body.objectUrl
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding:utf-8
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
@ -335,5 +338,25 @@ def get_current_week(s_date):
|
|||||||
return sunday
|
return sunday
|
||||||
|
|
||||||
|
|
||||||
|
from win32com import client
|
||||||
|
|
||||||
|
|
||||||
|
# 转换doc/docx为pdf
|
||||||
|
def doc2pdf(fn, path_data, filename):
|
||||||
|
# """
|
||||||
|
# :param fn: 'C:\Users\86173\Desktop\陈超峰.docx'
|
||||||
|
# :param path_data:'C:\Users\86173\Desktop\\'
|
||||||
|
# :param filename:陈超峰.docx
|
||||||
|
# :return: 'C:\Users\86173\Desktop\陈超峰.pdf'
|
||||||
|
# """
|
||||||
|
new_filename=filename.split('.')[0]
|
||||||
|
word = client.Dispatch("Word.Application") # 打开word应用程序
|
||||||
|
doc = word.Documents.Open(fn) # 打开word文件
|
||||||
|
doc.SaveAs("{}/{}.pdf".format(path_data, new_filename), 17) # 另存为后缀为".pdf"的文件,其中参数17表示为pdf
|
||||||
|
doc.Close() # 关闭原来word文件
|
||||||
|
word.Quit()
|
||||||
|
return path_data + '/' + new_filename + '.pdf',new_filename + '.pdf'
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
get_every_months('2022-01-01', '2022-12-31')
|
get_every_months('2022-01-01', '2022-12-31')
|
||||||
|
Loading…
Reference in New Issue
Block a user