diff --git a/backend/src/dashboard/scripts/quick_one.py b/backend/src/dashboard/scripts/quick_one.py new file mode 100644 index 0000000..ff63bb1 --- /dev/null +++ b/backend/src/dashboard/scripts/quick_one.py @@ -0,0 +1,32 @@ +# raise RuntimeError("this should never run in production") +# Never run this in a workflow. +# It is only for debugging/local development + + +import asyncio +import json +from tqdm import tqdm +from dashboard.services.hubspot_client import Pipeline +from dashboard.services.hubspot_client_async import HubSpotClientAsync +from dashboard.services.file_manager import FileManager +from datetime import datetime + + + +async def main(): + hubspot = HubSpotClientAsync() + # https://app-eu1.hubspot.com/contacts/145275138/record/0-3/370193175794 + deal_id = "263490768079" + tasks = [asyncio.create_task(hubspot.from_deal_get_info(deal_id))] + results = [] + + + for task in asyncio.as_completed(tasks): + result = await task + results.append(result) + return results + + +if __name__ == "__main__": + result = await main() + result[0]["attempts"] diff --git a/backend/src/dashboard/services/hubspot_client_async.py b/backend/src/dashboard/services/hubspot_client_async.py index 2cf5370..cd7d9ba 100644 --- a/backend/src/dashboard/services/hubspot_client_async.py +++ b/backend/src/dashboard/services/hubspot_client_async.py @@ -131,11 +131,15 @@ class HubSpotClientAsync: 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) if company_id else {} + appointments = await self.from_deal_get_appointments(deal_id) + + return { "deal_properties": deal_info, "line_items": line_items, "company_info": company_info, + "attempts": appointments, } # ----------------------------------- @@ -236,3 +240,56 @@ class HubSpotClientAsync: except Exception: self.logger.warning(f"Line items missing for deal {deal_id}") return [] + + async def from_deal_get_associated_meetings(self, deal_id: str): + associations = self.client.crm.associations.v4.basic_api + + # Object type "0-4" = Meetings (Appointments) + response = await self._run( + associations.get_page, + "deals", + deal_id, + "0-421", + limit=100, + ) + + if not response.results: + return [] + + meeting_ids = [row.to_object_id for row in response.results] + return meeting_ids + + async def get_meeting_info(self, meeting_id: str): + meetings_api = self.client.crm.objects.basic_api + + meeting = await self._run( + meetings_api.get_by_id, + "0-421", # meeting object type + meeting_id, + properties=[ + "hs_appointment_name", + "assigned_surveyor", + "outcome_from_deal", + "outcome__cloned_", + "outcome_surveyor", + "ecd_from_deal", + "submission_date" + ] + ) + + return meeting.properties + + + async def from_deal_get_appointments(self, deal_id: str): + meeting_ids = await self.from_deal_get_associated_meetings(deal_id) + + tasks = [ + asyncio.create_task(self.get_meeting_info(meeting_id)) + for meeting_id in meeting_ids + ] + + results = [] + for task in asyncio.as_completed(tasks): + results.append(await task) + + return results diff --git a/run_backend.sh b/run_backend.sh old mode 100644 new mode 100755 diff --git a/run_quick.sh b/run_quick.sh new file mode 100755 index 0000000..d344dfa --- /dev/null +++ b/run_quick.sh @@ -0,0 +1 @@ +cd backend && poetry run python src/dashboard/scripts/quick_one.py