diff --git a/examples/input.json b/examples/input.json index c5ac471..b6be293 100644 --- a/examples/input.json +++ b/examples/input.json @@ -1,8 +1,10 @@ { "client_name": "Acme Ltd", - "provider_name": "John Doe 2", + "provider_name": "Will Smith", "payment_type": "hourly", "hourly_rate_gbp": 40, "include_confidentiality": false, + "include_ip_clause": false, + "termination_notice_days": 14, "governing_law": "England and Wales" } \ No newline at end of file diff --git a/main.py b/main.py index 834745f..f7a61a4 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,17 @@ import json from pathlib import Path from jinja2 import Environment, FileSystemLoader +from schema import DocumentInput + def main(): # load input data # path() over hardcoding str data = json.loads(Path("examples/input.json").read_text(encoding="utf-8")) + # validate + normalise input + doc_input = DocumentInput(**data) + # setup template eng # create jinja2 env for templates env = Environment( @@ -20,7 +25,7 @@ def main(): # load template to render # **data spreads dict so keys become template vars template = env.get_template("doc.md.j2") - out = template.render(**data) + out = template.render(**doc_input.model_dump()) # write output - render md to file Path("out.md").write_text(out, encoding="utf-8") diff --git a/schema.py b/schema.py new file mode 100644 index 0000000..04451f5 --- /dev/null +++ b/schema.py @@ -0,0 +1,16 @@ +from typing import Literal, Optional + +from pydantic import BaseModel, Field + + +class DocumentInput(BaseModel): + client_name: str = Field(..., min_length=1) + provider_name: str = Field(..., min_length=1) + + payment_type: Literal["hourly", "fixed", "other"] + + hourly_rate_gbp: Optional[float] = Field(None, gt=0) + fixed_fee_gbp: Optional[float] = Field(None, gt=0) + + include_confidentiality: bool = False + governing_law: str \ No newline at end of file diff --git a/templates/doc.md.j2 b/templates/doc.md.j2 index a72a3e0..2fb18c5 100644 --- a/templates/doc.md.j2 +++ b/templates/doc.md.j2 @@ -24,4 +24,14 @@ not included. laws of england and wales. {% else %} {{ governing_law }}. -{% endif %} \ No newline at end of file +{% endif %} + +## intellectual property +{% if include_ip_clause %} +all intellectual property created during the services remains with the provider. +{% else %} +no intellectual property clause is included. +{% endif %} + +## termination +either party may terminate this agreement with {{ termination_notice_days }} days' written notice.