mirror of
https://github.com/Hestia-Homes/insight.git
synced 2026-06-08 11:17:25 +00:00
run it now
This commit is contained in:
parent
8ee94d72ad
commit
9f2d99ea5f
1 changed files with 33 additions and 27 deletions
|
|
@ -13,6 +13,8 @@ class HubSpotClientAsync:
|
|||
self.access_token = "pat-eu1-064f7f5c-a7d8-4d93-a9b2-b604da6164a6"
|
||||
self.client = hubspot.Client.create(access_token=self.access_token)
|
||||
self.all_deals = None
|
||||
self._company_cache: dict[str, dict] = {}
|
||||
|
||||
|
||||
# cleaner logging — only warning+error by default
|
||||
logging.basicConfig(
|
||||
|
|
@ -111,38 +113,31 @@ class HubSpotClientAsync:
|
|||
# Deal Info
|
||||
# -----------------------------------
|
||||
async def from_deal_get_info(self, deal_id):
|
||||
deal = await self._run(
|
||||
deal_task = self._run(
|
||||
self.client.crm.deals.basic_api.get_by_id,
|
||||
deal_id,
|
||||
properties=[
|
||||
'dealname',
|
||||
'dealstage',
|
||||
'expected_commencement_date',
|
||||
'last_submission_date',
|
||||
'mtp_planned_week',
|
||||
'mtp_completion_date',
|
||||
'design_planned_week',
|
||||
'retrofit_design_status',
|
||||
'design_completion_date',
|
||||
'item_id__monday_com_',
|
||||
'funding_type',
|
||||
'coordination_status__stage_1_',
|
||||
'expected_project_start_date',
|
||||
'expected_project_end_date'
|
||||
]
|
||||
properties=[...]
|
||||
)
|
||||
|
||||
history_task = self.get_expected_commencement_history(deal_id)
|
||||
line_items_task = self.from_deal_get_line_items(deal_id)
|
||||
company_id_task = self.from_deal_get_associated_company_id(deal_id)
|
||||
appointments_task = self.from_deal_get_appointments(deal_id)
|
||||
|
||||
deal, history, line_items, company_id, appointments = await asyncio.gather(
|
||||
deal_task,
|
||||
history_task,
|
||||
line_items_task,
|
||||
company_id_task,
|
||||
appointments_task,
|
||||
)
|
||||
|
||||
company_info = await self.get_company_information(company_id)
|
||||
|
||||
deal_info = dict(deal.properties)
|
||||
deal_info["deal_id"] = deal_id
|
||||
deal_info["expected_commencement_history"] = history
|
||||
|
||||
expected_commencement_history = await self.get_expected_commencement_history(deal_id)
|
||||
deal_info["expected_commencement_history"] = expected_commencement_history
|
||||
|
||||
line_items = await self.from_deal_get_line_items(deal_id)
|
||||
company_id = await self.from_deal_get_associated_company_id(deal_id)
|
||||
company_info = await self.get_company_information(company_id)
|
||||
appointments = await self.from_deal_get_appointments(deal_id)
|
||||
|
||||
return {
|
||||
"deal_properties": deal_info,
|
||||
"line_items": line_items,
|
||||
|
|
@ -159,12 +154,23 @@ class HubSpotClientAsync:
|
|||
"name": "NO COMPANY ASSOCIATION IN HUBSPOT - FIX ME"
|
||||
}
|
||||
|
||||
# ✅ cache hit
|
||||
if company_id in self._company_cache:
|
||||
return self._company_cache[company_id]
|
||||
|
||||
# ❌ cache miss → fetch once
|
||||
company = await self._run(
|
||||
self.client.crm.companies.basic_api.get_by_id,
|
||||
company_id,
|
||||
properties=['name']
|
||||
properties=["name"]
|
||||
)
|
||||
return company.properties
|
||||
|
||||
props = company.properties
|
||||
|
||||
# ✅ store in cache
|
||||
self._company_cache[company_id] = props
|
||||
|
||||
return props
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue