MrKAMELEON/ReferencesExtractor
0
1from pathlib import Path2 3from tqdm import tqdm4 5from file_handler import fetch_files, find_references, load_pdf_content, save_references6from software_extractor import format_references7 8 9def process_single_pdf(pdf_path: Path) -> str:10 """Process a single PDF file and save its references.11 12 Args:13 pdf_path: Path to the PDF file to process14 output_path: Path where to save the extracted references15 16 Returns:17 Flattened references as a string18 """19 file_content = load_pdf_content(pdf_path)20 references = find_references(file_content)21 22 formatted_references = format_references(references)23 if formatted_references is None:24 tqdm.write(f"{pdf_path.name}: References formatting failed!")25 return26 27 flattened_references = "\n".join(formatted_references)28 return flattened_references29 30 31def main(input_directory: Path, output_directory: Path) -> None:32 """Process all PDF files in the input directory and save extracted references.33 34 Args:35 input_directory: Directory containing PDF files to process36 output_directory: Directory where to save the extracted references37 """38 pdf_files = fetch_files(input_directory)39 print(f"\nFound {len(pdf_files)} PDF files to process")40 41 for pdf_file in tqdm(pdf_files, desc="Processing PDFs", unit="file"):42 pdf_path = input_directory / pdf_file43 output_path = output_directory / f"Bibliografia {pdf_file}".replace(".pdf", ".txt")44 flattened_references = process_single_pdf(pdf_path)45 save_references(output_path, flattened_references)46 47 48if __name__ == "__main__":49 input_directory = Path("./input_files")50 output_directory = Path("./output_files")51 main(input_directory, output_directory)52 