trigger via sqs from local file

This commit is contained in:
Daniel Roth 2026-05-14 13:37:08 +00:00
parent c98fc8452f
commit 03ae73f39a

View file

@ -0,0 +1,103 @@
import json
import logging
import os
from typing import Any, Optional, cast
import boto3
from openpyxl import load_workbook
from backend.app.config import get_settings
from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
PashubToAraTriggerRequest,
)
logging.basicConfig(level=logging.INFO, format="%(message)s")
logger: logging.Logger = logging.getLogger(__name__)
DRY_RUN: bool = True
EXCEL_PATH: str = os.path.join(
os.path.dirname(__file__),
"united-infrastructure-exports-all-deals-2026-05-14.xlsx",
)
def _build_requests(excel_path: str) -> list[PashubToAraTriggerRequest]:
wb = load_workbook(excel_path, data_only=True)
ws = wb.worksheets[0]
headers: dict[str, int] = {}
for col in range(1, ws.max_column + 1):
header_val = ws.cell(row=1, column=col).value
if header_val is not None:
headers[str(header_val).strip()] = col
pashub_col: int = headers["PasHub link"]
record_id_col: int = headers["Record ID"]
deal_name_col: int = headers["Deal Name"]
deal_stage_col: int = headers["Deal Stage"]
requests: list[PashubToAraTriggerRequest] = []
for row in range(2, ws.max_row + 1):
pashub_link_raw = ws.cell(row=row, column=pashub_col).value
if not pashub_link_raw:
continue
pashub_link: str = str(pashub_link_raw).strip()
record_id_raw = ws.cell(row=row, column=record_id_col).value
deal_name_raw = ws.cell(row=row, column=deal_name_col).value
deal_stage_raw = ws.cell(row=row, column=deal_stage_col).value
hubspot_deal_id: Optional[str] = (
str(record_id_raw) if record_id_raw is not None else None
)
address: Optional[str] = (
str(deal_name_raw).strip() if deal_name_raw is not None else None
)
deal_stage: Optional[str] = (
str(deal_stage_raw).strip() if deal_stage_raw is not None else None
)
requests.append(
PashubToAraTriggerRequest(
pashub_link=pashub_link,
hubspot_deal_id=hubspot_deal_id,
address=address,
deal_stage=deal_stage,
)
)
return requests
def main() -> None:
trigger_requests: list[PashubToAraTriggerRequest] = _build_requests(EXCEL_PATH)
sqs: Any = cast(Any, boto3.client("sqs")) # type: ignore[reportUnknownMemberType]
queue_url: str = get_settings().PASHUB_TO_ARA_SQS_URL
count: int = 0
for request in trigger_requests:
action: str = "DRY RUN" if DRY_RUN else "SENDING"
logger.info(
f"[{action}] deal_id={request.hubspot_deal_id} pashub_link={request.pashub_link}"
)
if not DRY_RUN:
response: dict[str, Any] = sqs.send_message(
QueueUrl=queue_url,
MessageBody=json.dumps(request.model_dump()),
)
message_id: str = response["MessageId"]
logger.info(f" MessageId: {message_id}")
count += 1
label: str = "would send" if DRY_RUN else "sent"
print(f"{count} messages {label}")
if __name__ == "__main__":
main()