changes docx导出接口
This commit is contained in:
parent
8fbc74981b
commit
614b3c8e4a
File diff suppressed because one or more lines are too long
|
@ -3,6 +3,7 @@ import os.path
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from ahocorasick import Automaton
|
||||||
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
||||||
from docx.oxml.ns import qn
|
from docx.oxml.ns import qn
|
||||||
from docx.shared import Pt, Length, Inches
|
from docx.shared import Pt, Length, Inches
|
||||||
|
@ -254,7 +255,7 @@ def daily_export_to_pdf(req: DailySchemas.DailyExportToPdfReq, db: Session = Dep
|
||||||
for key, val in trends.items():
|
for key, val in trends.items():
|
||||||
val_list = [key]
|
val_list = [key]
|
||||||
for index, item in enumerate(val):
|
for index, item in enumerate(val):
|
||||||
idx = str(index+1) + '、' + item
|
idx = str(index + 1) + '、' + item
|
||||||
val_list.append(idx)
|
val_list.append(idx)
|
||||||
val_list.append('{{{{{}}}}}'.format(item))
|
val_list.append('{{{{{}}}}}'.format(item))
|
||||||
list_write_docx(write_list=val_list, tep_doc=dt_doc)
|
list_write_docx(write_list=val_list, tep_doc=dt_doc)
|
||||||
|
@ -401,3 +402,26 @@ def daily_export_to_pdf(req: DailySchemas.DailyExportToPdfReq, db: Session = Dep
|
||||||
file_name = "运行日报{}.docx".format(date_string)
|
file_name = "运行日报{}.docx".format(date_string)
|
||||||
file_path = f"{temp_path}/{file_name}"
|
file_path = f"{temp_path}/{file_name}"
|
||||||
return {"url": "/" + file_path}
|
return {"url": "/" + file_path}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/sensitive_word_verification", summary="敏感词校验")
|
||||||
|
def daily_export_to_pdf(word_str: str):
|
||||||
|
json_filepath = os.path.join(os.getcwd(), 'Config', 'sensitive_word.json')
|
||||||
|
# 将列表保存为 json 文件
|
||||||
|
with open(json_filepath, 'r', encoding='utf-8') as json_file:
|
||||||
|
words = json.load(json_file)
|
||||||
|
|
||||||
|
class SensitiveWordChecker:
|
||||||
|
def __init__(self, sensitive_words):
|
||||||
|
self.automaton = Automaton()
|
||||||
|
for idx, word in enumerate(sensitive_words):
|
||||||
|
self.automaton.add_word(word, (idx, word))
|
||||||
|
self.automaton.make_automaton()
|
||||||
|
|
||||||
|
def check(self, text):
|
||||||
|
return {item for _, item in self.automaton.iter(text)}
|
||||||
|
|
||||||
|
checker = SensitiveWordChecker(words)
|
||||||
|
|
||||||
|
sensitive_words_in_text = checker.check(word_str)
|
||||||
|
return sensitive_words_in_text
|
||||||
|
|
Loading…
Reference in New Issue