Code clean
This commit is contained in:
@@ -2,6 +2,7 @@ import operator
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
||||
import fitz # PyMuPDF
|
||||
from pypdf import PdfReader
|
||||
|
||||
|
||||
@@ -11,3 +12,20 @@ def check_pdf_pages(pdf_file: str, rules: Dict[str, Any]) -> float:
|
||||
reader = PdfReader(pdf_file)
|
||||
nb_pages: int = len(reader.pages)
|
||||
return float(getattr(operator, rules["relation"])(nb_pages, rules["ref_value"]))
|
||||
|
||||
|
||||
def extract_answers_from_pdf(pdf_file):
|
||||
doc = fitz.open(pdf_file)
|
||||
answers = []
|
||||
|
||||
for page in doc:
|
||||
text = page.get_text()
|
||||
lines = text.split('\n')
|
||||
for line in lines:
|
||||
if line.strip():
|
||||
parts = line.split('=')
|
||||
if len(parts) > 1:
|
||||
answer = parts[-1].strip()
|
||||
answers.append(answer)
|
||||
|
||||
return answers
|
||||
|
||||
Reference in New Issue
Block a user