华为云和解析
This commit is contained in:
parent
3d4add27e4
commit
73d76d56c6
@ -2,6 +2,7 @@ import operator
|
||||
import os
|
||||
import re
|
||||
from typing import Any
|
||||
from obs import ObsClient
|
||||
|
||||
import pandas as pd
|
||||
import pymongo
|
||||
@ -16,6 +17,7 @@ from core.config import settings
|
||||
from core.security import get_password_hash
|
||||
from utils.dingding import *
|
||||
from utils.jianli import get_resume
|
||||
from utils.func import get_uid
|
||||
import crud, schemas
|
||||
from datetime import datetime
|
||||
from core.configuration import *
|
||||
@ -27,6 +29,13 @@ from utils import get_time, qujian_time, Download_xlsx, send_str_mail
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# 创建ObsClient实例
|
||||
obsClient = ObsClient(
|
||||
access_key_id='UPEO770G619UPU8TU61Y',
|
||||
secret_access_key='M7zVRT1pjRtGSZ2TOZwKBRoVJLeWAOf633kHaNcu',
|
||||
server='obs.cn-east-2.myhuaweicloud.com'
|
||||
)
|
||||
|
||||
|
||||
# 面试查询
|
||||
@router.post("/interview_find")
|
||||
@ -164,59 +173,154 @@ async def interview_insert(
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
|
||||
|
||||
# 导入面试数据
|
||||
@router.post("/interview_file_insert")
|
||||
async def interview_file_insert(
|
||||
# 转存简历到华为云
|
||||
@router.post("/file_to_hw")
|
||||
async def file_to_hw(
|
||||
request: Request,
|
||||
file: UploadFile = File(...),
|
||||
db: CKDrive = Depends(get_ck_db)
|
||||
) -> schemas.Msg:
|
||||
""" interview面试数据导入 """
|
||||
path_data = os.getcwd() + '/jianli/' # 当前文件所在的目录
|
||||
""" 简历上传到华为云 """
|
||||
path_data = os.getcwd() + '/jianli' # 当前文件所在的目录
|
||||
if not os.path.exists(path_data):
|
||||
os.makedirs(path_data)
|
||||
contents = await file.read()
|
||||
filename = file.filename
|
||||
try:
|
||||
with open(path_data + filename, "wb") as f:
|
||||
with open(path_data + '/' + filename, "wb") as f:
|
||||
# 将获取的file文件内容,写入到新文件中
|
||||
f.write(contents)
|
||||
f.close()
|
||||
except:
|
||||
return schemas.Msg(code=400, msg='上传文件有误', data=None)
|
||||
data = get_resume(filename, path_data)
|
||||
education = data['education']
|
||||
# 学历int转化
|
||||
education_int = {
|
||||
'大专': 1,
|
||||
'本科': 2,
|
||||
'研究生': 3,
|
||||
'博士': 4,
|
||||
'硕士': 5,
|
||||
}
|
||||
if education and isinstance(education, str):
|
||||
data['education'] = education_int.get(education, 1)
|
||||
age = data['age']
|
||||
if not age:
|
||||
data['age'] = 20
|
||||
# 年龄int转化
|
||||
if age and isinstance(age, str):
|
||||
true_age = re.search(r"\d+\.?\d*", age)
|
||||
if len(true_age.group()) > 2:
|
||||
data['age'] = 20
|
||||
|
||||
try:
|
||||
res = obsClient.putFile('legu-cdn-source', 'hrms/' + filename, path_data + '/' + filename)
|
||||
|
||||
if res.status < 300:
|
||||
# 地址
|
||||
url = res.body.objectUrl
|
||||
# 简历初始文档
|
||||
data_mode = {
|
||||
"interview_name": "",
|
||||
"interview_type": 1,
|
||||
"interview_sign": 0,
|
||||
"hope_money": "",
|
||||
"feedback": 0,
|
||||
"interview_round": 0,
|
||||
"event_time": datetime.now(),
|
||||
"name": "",
|
||||
"phone": "",
|
||||
"job_name": "",
|
||||
"hr_name": "",
|
||||
"work_exp": 0,
|
||||
"interview_stage": 1,
|
||||
"owner_name": 2,
|
||||
"education": 1,
|
||||
"work_undergo": [],
|
||||
"project_undergo": [],
|
||||
"work_list": [],
|
||||
"school": "",
|
||||
"at_school": "",
|
||||
"specialty": "",
|
||||
"specialty_do": [],
|
||||
"mmended_state": 0,
|
||||
"mail": "",
|
||||
"account": "",
|
||||
"id_card": "",
|
||||
"gender": "",
|
||||
"age": 0,
|
||||
"gam": "",
|
||||
"interview_state": 1,
|
||||
"counts": 1,
|
||||
"nation": "汉",
|
||||
"review": [],
|
||||
"upgrade": [],
|
||||
"come_time": "",
|
||||
"now_money": "",
|
||||
"men_state": 1,
|
||||
"teacher_state": 1,
|
||||
"teacher_back": 1,
|
||||
"offer_state": 1,
|
||||
"offer_exam_state": 1,
|
||||
"notice_state": 1,
|
||||
"pass_why": 0,
|
||||
"pass_text": [],
|
||||
"file_url": url,
|
||||
}
|
||||
uid = get_uid()
|
||||
data_mode['uid'] = uid
|
||||
sql = f"insert into HR.resumes(interview_name, interview_type, interview_sign, hope_money, feedback," \
|
||||
f" interview_round, event_time, uid, name, phone, job_name, hr_name, work_exp, interview_stage, owner_name," \
|
||||
f" education, work_undergo, project_undergo, work_list, school, at_school, specialty, specialty_do, " \
|
||||
f"mmended_state, mail, account, id_card, gender, age, gam, interview_state, counts, nation, come_time," \
|
||||
f" review, upgrade, now_money, men_state, teacher_state, teacher_back, offer_state, offer_exam_state," \
|
||||
f" notice_state, pass_why, pass_text, file_url) values"
|
||||
# 存数据
|
||||
await db.execute_dict(sql, [data_mode])
|
||||
resData = {'file_url': url, 'filename': 'hrms/' + filename, 'uid': uid}
|
||||
return schemas.Msg(code=0, msg='ok', data=resData)
|
||||
else:
|
||||
data['age'] = int(true_age.group())
|
||||
work_exp = data['work_exp']
|
||||
if not work_exp:
|
||||
data['work_exp'] = 0
|
||||
# 工作经验float转化
|
||||
if work_exp and isinstance(work_exp, str):
|
||||
true_work_exp = re.search(r"\d+\.?\d*", work_exp)
|
||||
if len(true_work_exp.group()) > 3:
|
||||
data['work_exp'] = 0
|
||||
else:
|
||||
data['work_exp'] = float(true_work_exp.group())
|
||||
print(data)
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
print('errorCode:', res.errorCode)
|
||||
print('errorMessage:', res.errorMessage)
|
||||
return schemas.Msg(code=400, msg='上传华为云失败', data=None)
|
||||
except:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
return schemas.Msg(code=400, msg='上传华为云失败', data=None)
|
||||
|
||||
|
||||
# 导入面试数据
|
||||
@router.post("/interview_file_insert")
|
||||
async def interview_file_insert(
|
||||
request: Request,
|
||||
filenames: str,
|
||||
) -> schemas.Msg:
|
||||
""" interview面试数据导入 """
|
||||
path_data = os.getcwd() + '/jianli' # 当前文件所在的目录
|
||||
if not os.path.exists(path_data):
|
||||
os.makedirs(path_data)
|
||||
filename = filenames.split('/')[-1]
|
||||
try:
|
||||
res = obsClient.getObject('legu-cdn-source', filenames, path_data + '/' + filename)
|
||||
if res.status < 300:
|
||||
|
||||
data = get_resume(filename, path_data)
|
||||
education = data['education']
|
||||
# 学历int转化
|
||||
education_int = {
|
||||
'大专': 1,
|
||||
'本科': 2,
|
||||
'研究生': 3,
|
||||
'博士': 4,
|
||||
'硕士': 5,
|
||||
}
|
||||
if education and isinstance(education, str):
|
||||
data['education'] = education_int.get(education, 1)
|
||||
age = data['age']
|
||||
if not age:
|
||||
data['age'] = 20
|
||||
# 年龄int转化
|
||||
if age and isinstance(age, str):
|
||||
true_age = re.search(r"\d+\.?\d*", age)
|
||||
if len(true_age.group()) > 2:
|
||||
data['age'] = 20
|
||||
else:
|
||||
data['age'] = int(true_age.group())
|
||||
work_exp = data['work_exp']
|
||||
if not work_exp:
|
||||
data['work_exp'] = 0
|
||||
# 工作经验float转化
|
||||
if work_exp and isinstance(work_exp, str):
|
||||
true_work_exp = re.search(r"\d+\.?\d*", work_exp)
|
||||
if len(true_work_exp.group()) > 3:
|
||||
data['work_exp'] = 0
|
||||
else:
|
||||
data['work_exp'] = float(true_work_exp.group())
|
||||
print(data)
|
||||
return schemas.Msg(code=200, msg='ok', data=data)
|
||||
except:
|
||||
return schemas.Msg(code=400, msg='解析失败', data=None)
|
||||
|
||||
|
||||
@router.post("/add_job")
|
||||
@ -1059,6 +1163,7 @@ async def add_policy(
|
||||
await crud.api_module.update_one_module(db, res)
|
||||
return schemas.Msg(code=0, msg='修改成功', data='')
|
||||
|
||||
|
||||
@router.get("/api_module")
|
||||
async def domain_list(
|
||||
request: Request,
|
||||
@ -1069,10 +1174,10 @@ async def domain_list(
|
||||
角色管理创建角色时显示的各个模块
|
||||
"""
|
||||
res = await crud.api_module.get_api_module(db)
|
||||
api_module=[]
|
||||
api_module = []
|
||||
for i in res:
|
||||
if i['path_name'] !='root':
|
||||
data=[]
|
||||
if i['path_name'] != 'root':
|
||||
data = []
|
||||
data.append(i['auth_id'])
|
||||
data.append(i['path_name'])
|
||||
api_module.append(data)
|
||||
@ -1117,4 +1222,4 @@ async def add_api(
|
||||
await crud.api_module.insert_quanxian(db, schemas.Url_module(auth_id=auth_id, path_name=data_in.name,
|
||||
api_list=[data_in.path],
|
||||
api_name=[data_in.desc], state=[True]))
|
||||
return schemas.Msg(code=0, msg='ok', data='路由添加成功!')
|
||||
return schemas.Msg(code=0, msg='ok', data='路由添加成功!')
|
||||
|
@ -68,7 +68,7 @@ class InterviewDo:
|
||||
def insert_interview_sql(self):
|
||||
# 简历初始文档
|
||||
data_mode = {
|
||||
"interview_name": "吴操",
|
||||
"interview_name": "",
|
||||
"interview_type": 1,
|
||||
"interview_sign": 0,
|
||||
"hope_money": "",
|
||||
@ -78,7 +78,7 @@ class InterviewDo:
|
||||
"name": "",
|
||||
"phone": "",
|
||||
"job_name": "",
|
||||
"hr_name": "吴操",
|
||||
"hr_name": "",
|
||||
"work_exp": 0,
|
||||
"interview_stage": 1,
|
||||
"owner_name": 2,
|
||||
@ -112,6 +112,7 @@ class InterviewDo:
|
||||
"notice_state": 1,
|
||||
"pass_why": 0,
|
||||
"pass_text": [],
|
||||
"file_url": '',
|
||||
}
|
||||
|
||||
insert_data = []
|
||||
@ -126,7 +127,7 @@ class InterviewDo:
|
||||
f" education, work_undergo, project_undergo, work_list, school, at_school, specialty, specialty_do, " \
|
||||
f"mmended_state, mail, account, id_card, gender, age, gam, interview_state, counts, nation, come_time," \
|
||||
f" review, upgrade, now_money, men_state, teacher_state, teacher_back, offer_state, offer_exam_state," \
|
||||
f" notice_state, pass_why, pass_text) values"
|
||||
f" notice_state, pass_why, pass_text, file_url) values"
|
||||
now_time = datetime.datetime.now()
|
||||
for data in insert_data:
|
||||
s1 = data['event_time']
|
||||
|
@ -20,7 +20,7 @@ schema_dict = {'姓名': 'name', '所在地': 'account', '户口所在地': 'acc
|
||||
|
||||
# 简历初始文档
|
||||
data_mode = {
|
||||
"interview_name": "吴操",
|
||||
"interview_name": "",
|
||||
"interview_type": 1,
|
||||
"interview_sign": 0,
|
||||
"hope_money": "",
|
||||
@ -30,7 +30,7 @@ data_mode = {
|
||||
"name": "",
|
||||
"phone": "",
|
||||
"job_name": "",
|
||||
"hr_name": "吴操",
|
||||
"hr_name": "",
|
||||
"work_exp": 0,
|
||||
"interview_stage": 1,
|
||||
"owner_name": 2,
|
||||
@ -64,6 +64,7 @@ data_mode = {
|
||||
"notice_state": 1,
|
||||
"pass_why": 0,
|
||||
"pass_text": [],
|
||||
"file_url": '',
|
||||
}
|
||||
|
||||
|
||||
@ -140,8 +141,10 @@ def pdf_docx(url, filename):
|
||||
docx_name = url + f"/{file_name}.docx"
|
||||
# 加载pdf文档
|
||||
cv = Converter(pdf_name)
|
||||
cv.convert(docx_name, start=0, end=12)
|
||||
cv.convert(docx_name, start=0, end=None)
|
||||
cv.close()
|
||||
# comand = f'$ pdf2docx convert {pdf_name} {docx_name}'
|
||||
# os.system(comand)
|
||||
|
||||
|
||||
def getText_pdf(filename):
|
||||
@ -477,4 +480,7 @@ def get_resume(file, path_data):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
get_resume(file, path_data)
|
||||
path_data = "D:\wokerplay\面试简历1"
|
||||
for _, _, files in os.walk(path_data):
|
||||
for file in files:
|
||||
print(get_resume(file, path_data))
|
||||
|
Loading…
Reference in New Issue
Block a user