FOIA_Doc_Search / appeals /pdf_appeal.py
GodsDevProject's picture
Rename pdf_appeal.py to appeals/pdf_appeal.py
457e302 verified
# appeals/pdf_appeal.py
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.pagesizes import LETTER
from datetime import date
def generate_appeal_text(
agency: str,
subject: str,
rationale: str
) -> str:
return f"""
FOIA APPEAL
Agency: {agency}
Date: {date.today().isoformat()}
This appeal concerns a Freedom of Information Act request regarding:
"{subject}"
Grounds for Appeal:
{rationale}
The requester respectfully seeks reconsideration under FOIA,
noting that similar records have previously been released and that
this appeal makes no claim regarding classified or undisclosed activity.
Sincerely,
Requester
""".strip()
def export_appeal_pdf(
agency: str,
subject: str,
rationale: str,
out_path: str = "/tmp/foia_appeal.pdf"
) -> str:
styles = getSampleStyleSheet()
doc = SimpleDocTemplate(out_path, pagesize=LETTER)
story = []
text = generate_appeal_text(agency, subject, rationale)
for para in text.split("\n\n"):
story.append(Paragraph(para.replace("\n", "<br/>"), styles["BodyText"]))
story.append(Spacer(1, 12))
doc.build(story)
return out_path