Model/etl/hubspot/scripts/scraper/main.py
2026-04-08 14:48:17 +00:00

39 lines
1.4 KiB
Python

from backend.app.db.models.organisation import HubspotDealData
from etl.hubspot.hubspotClient import HubspotClient
from etl.hubspot.hubspotDataTodB import CompanyData, HubspotDataToDb
from backend.utils.subtasks import task_handler
from typing import Any, Dict, Optional
@task_handler()
def handler(body: dict[str, Any], context: Any) -> None:
hubspot_deal_id = body.get("hubspot_deal_id", "")
if hubspot_deal_id == "":
raise RuntimeError(
"Missing Hubspot Deal ID in SQS body request, 'hubspot_deal_id'"
)
hubspot_deal_id = "327170793707"
hubspot_client = HubspotClient()
db_client = HubspotDataToDb()
db_deal: Optional[HubspotDealData] = db_client.find_deal_with_deal_id(
hubspot_deal_id
)
if db_deal:
db_client.update_deal_with_checks(db_deal, hubspot_client)
else:
hubspot_deal: Dict[str, str]
company: Optional[str]
listing: Optional[dict[str, str]]
hubspot_deal, company, listing = hubspot_client.get_deal_company_listing(
hubspot_deal_id
)
if company:
company_data: CompanyData = hubspot_client.get_company_information(company)
db_client: HubspotDataToDb = HubspotDataToDb()
db_client.upsert_company(company_data)
db_client.upsert_deal(hubspot_deal, company, listing, hubspot_client)