added hubspot company data

This commit is contained in:
Jun-te Kim 2026-03-24 15:43:10 +00:00
parent a362e1dd99
commit 29ab9ecfd7
3 changed files with 18 additions and 12 deletions

View file

@ -25,6 +25,7 @@ from hubspot.crm.associations.v4.models import ( # type: ignore[reportMissingTy
ForwardPaging as AssociationsPaging,
NextPage as AssociationsPagingNext,
)
from etl.hubspot.hubspotDataTodB import CompanyData
from backend.app.config import get_settings
@ -223,7 +224,7 @@ class HubspotClient:
return deal, company, listing
def get_company_information(self, company_id: str) -> dict[str, str]:
def get_company_information(self, company_id: str) -> CompanyData:
companies_api: CompaniesBasicApi = self.client.crm.companies.basic_api # type: ignore[reportUnknownMemberType]
company: HubspotObject = companies_api.get_by_id( # type: ignore[reportUnknownMemberType]
@ -233,7 +234,7 @@ class HubspotClient:
],
)
company_info: dict[str, str] = cast(dict[str, str], company.properties) # type: ignore[reportUnknownMemberType]
company_info: CompanyData = company.properties # type: ignore[reportUnknownMemberType]
return company_info
def get_all_pipelines(self) -> list[dict[str, str]]:

View file

@ -1,4 +1,4 @@
from backend.app.db.connection import db_session
from backend.app.db.connection import db_read_session
from backend.app.db.models.organisation import Organisation
from sqlmodel import select
from datetime import datetime, timezone
@ -15,13 +15,18 @@ class HubspotDataToDb:
pass
def read_org_table(self, limit: int = 10):
with db_session() as session:
with db_read_session() as session:
records = session.exec(select(Organisation).limit(limit)).all()
return records
def get_org_names(self, limit: int = 10) -> list[str]:
"""Returns a list of organisation names."""
records = self.read_org_table(limit)
return [org.name for org in records if org.name]
def upsert_company(self, company_data: CompanyData) -> Organisation:
"""Upserts a company record. Updates if hubspot_company_id exists, otherwise creates new."""
with db_session() as session:
with db_read_session() as session:
hubspot_id = company_data.get("hs_object_id")
company_name = company_data.get("name")

View file

@ -1,19 +1,19 @@
from etl.hubspot.hubspotClient import HubspotClient, Companies
from etl.hubspot.hubspotDataTodB import HubspotDataToDb
from etl.hubspot.hubspotDataTodB import HubspotDataToDb, CompanyData
hubspot = HubspotClient()
dbRead = HubspotDataToDb()
companies_to_add_or_ensure_it_exists = [
Companies.THE_GUINESS_PARTNERSHIP,
Companies.SOUTHERN_HOUSING_GROUP,
]
for company in companies_to_add_or_ensure_it_exists:
company_info = hubspot.get_company_information(company.value)
company_info
break
company_info: CompanyData = hubspot.get_company_information(company.value)
dbRead.upsert_company(company_info)
dbRead = HubspotDataToDb()
dbRead.read_org_table()
names = dbRead.get_org_names()
print(f"Organisations in database: {names}")