mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from fastapi import APIRouter, Depends
|
|
from backend.app.dependencies import validate_token
|
|
from backend.app.plan.schemas import PlanTriggerRequest
|
|
from backend.app.utils import read_csv_from_s3, setup_logger
|
|
from backend.app.config import get_settings
|
|
from model_data.Property import Property
|
|
from epc_api.client import EpcClient
|
|
|
|
logger = setup_logger()
|
|
|
|
router = APIRouter(
|
|
prefix="/plan",
|
|
tags=["plan"],
|
|
dependencies=[Depends(validate_token)],
|
|
responses={404: {"description": "Not found"}}
|
|
)
|
|
|
|
|
|
@router.post("/trigger")
|
|
async def trigger_plan(body: PlanTriggerRequest):
|
|
logger.info("Getting the inputs")
|
|
# Read in the trigger file from s3
|
|
bucket_name = get_settings().PLAN_TRIGGER_BUCKET
|
|
plan_input = read_csv_from_s3(bucket_name=bucket_name, filepath=body.trigger_file_path)
|
|
print(plan_input)
|
|
|
|
epc_client = EpcClient(auth_token=get_settings().EPC_AUTH_TOKEN)
|
|
input_properties = [
|
|
Property(postcode=config['postcode'], address1=config['address'], epc_client=epc_client)
|
|
for config in plan_input
|
|
]
|
|
|
|
logger.info("Getting EPC data")
|
|
for p in input_properties:
|
|
p.search_address_epc()
|
|
p.set_year_built()
|
|
|
|
logger.info("Parsing and validating the file")
|
|
# TODO: Add validation
|
|
logger.info("properties")
|
|
logger.info(input_properties)
|
|
|
|
logger.info("Reading in EPC data")
|
|
|
|
return {"message": "Plan triggered"}
|