2024-07-28 16:16:52 +08:00
|
|
|
import time
|
2024-09-09 17:07:03 +08:00
|
|
|
import random
|
2025-02-27 19:35:25 +08:00
|
|
|
from src.utils.logging_config import logger
|
2024-07-14 18:31:23 +08:00
|
|
|
|
|
|
|
|
def is_text_pdf(pdf_path):
|
2024-07-16 18:14:27 +08:00
|
|
|
import fitz
|
2024-07-14 18:31:23 +08:00
|
|
|
doc = fitz.open(pdf_path)
|
|
|
|
|
for page_num in range(len(doc)):
|
|
|
|
|
page = doc.load_page(page_num)
|
|
|
|
|
text = page.get_text()
|
|
|
|
|
if text.strip(): # 检查是否有文本内容
|
|
|
|
|
return True
|
2024-07-14 23:59:52 +08:00
|
|
|
return False
|
|
|
|
|
|
2024-07-28 16:16:52 +08:00
|
|
|
def hashstr(input_string, length=8, with_salt=False):
|
2024-07-14 23:59:52 +08:00
|
|
|
import hashlib
|
2024-07-28 16:16:52 +08:00
|
|
|
# 添加时间戳作为干扰
|
|
|
|
|
if with_salt:
|
2024-09-09 17:07:03 +08:00
|
|
|
input_string += str(time.time() + random.random())
|
2024-07-28 16:16:52 +08:00
|
|
|
|
2024-07-14 23:59:52 +08:00
|
|
|
hash = hashlib.md5(str(input_string).encode()).hexdigest()
|
|
|
|
|
return hash[:length]
|