mirror of
https://github.com/Hestia-Homes/insight.git
synced 2026-06-08 11:17:25 +00:00
added appointments
This commit is contained in:
parent
a11490ea72
commit
9529d4814d
4 changed files with 90 additions and 0 deletions
32
backend/src/dashboard/scripts/quick_one.py
Normal file
32
backend/src/dashboard/scripts/quick_one.py
Normal file
|
|
@ -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"]
|
||||
|
|
@ -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
|
||||
|
|
|
|||
0
run_backend.sh
Normal file → Executable file
0
run_backend.sh
Normal file → Executable file
1
run_quick.sh
Executable file
1
run_quick.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
cd backend && poetry run python src/dashboard/scripts/quick_one.py
|
||||
Loading…
Add table
Reference in a new issue