File size: 1,001 Bytes
2ab2b76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Raw document extractors for institutional PDF notices and CSV schedules."""

import csv
from pathlib import Path
from typing import Dict, List

import pandas as pd
import pymupdf

from src.config import ROOT_DIR, SOURCE_MANIFEST_PATH


def load_manifest_rows(manifest_path: Path = SOURCE_MANIFEST_PATH) -> List[Dict[str, str]]:
    """Load source provenance rows from source_manifest.csv."""
    with manifest_path.open("r", encoding="utf-8", newline="") as f:
        return list(csv.DictReader(f))


def extract_pdf_text(file_path: str) -> str:
    """Extract raw text from all pages of a PDF notice."""
    pdf_path = ROOT_DIR / file_path
    doc = pymupdf.open(pdf_path)
    text = "\n".join(page.get_text("text") for page in doc)
    doc.close()
    return text


def extract_csv_rows(file_path: str) -> List[Dict[str, str]]:
    """Read structured fee/tier schedule rows from CSV."""
    csv_path = ROOT_DIR / file_path
    df = pd.read_csv(csv_path)
    return df.to_dict(orient="records")