diff --git a/etl/db/hubSpotLoad.py b/etl/db/hubSpotLoad.py index dd19fee..0582df6 100644 --- a/etl/db/hubSpotLoad.py +++ b/etl/db/hubSpotLoad.py @@ -1,5 +1,5 @@ from etl.db.db import get_db_session, init_db -from etl.models.topLevel import HubspotDealData +from etl.models.topLevel import HubspotDealData, HubspotCommpanyData class HubspotTodb(): def __init__(self): @@ -23,4 +23,15 @@ class HubspotTodb(): session.add(new_record) session.commit() session.refresh(new_record) + return new_record + + def new_record_company(self, company_data): + with get_db_session() as session: + new_record = HubspotCommpanyData( + company_id=company_data.get("hs_object_id"), + company_name=company_data.get("name") + ) + session.add(new_record) + session.commit() + session.refresh(new_record) return new_record \ No newline at end of file diff --git a/etl/hubSpotClient/hubspotClient.py b/etl/hubSpotClient/hubspotClient.py index 6b3a554..f8809a0 100644 --- a/etl/hubSpotClient/hubspotClient.py +++ b/etl/hubSpotClient/hubspotClient.py @@ -124,4 +124,13 @@ class HubSpotClient(): ) return deal.properties - \ No newline at end of file + + def get_company_information(self, company_id): + company = self.client.crm.companies.basic_api.get_by_id( + company_id, + properties=[ + 'name', + ] + ) + company_info = company.properties + return company_info \ No newline at end of file diff --git a/etl/hubSpotClient/hubspot_company.py b/etl/hubSpotClient/hubspot_company.py index 9dc4e4c..37c73ac 100644 --- a/etl/hubSpotClient/hubspot_company.py +++ b/etl/hubSpotClient/hubspot_company.py @@ -2,40 +2,13 @@ from etl.hubSpotClient.hubspotClient import HubSpotClient, Companies, Pipeline from tqdm import tqdm from etl.db.hubSpotLoad import HubspotTodb -''' -# TODO: - get one deal from db, from db - for avri only so far - add it to the db - show in frontend -''' - -# get ALL deals hubspot = HubSpotClient() # All deals from a pipeline_id via filter -deals = hubspot.get_deal_ids_by_pipeline( - pipeline_id=Pipeline.OPERATIONS_SOCIAL_HOUSING.value, - ) +company = hubspot.get_company_information(Companies.ABRI.value) -# deals from companies we care about -valueable_deals = [ - Companies.ABRI.value -] -deals_to_add = [] - - -deal_to_companies = {} loader = HubspotTodb() -# Get all deals we care about -for i,deal in enumerate(tqdm(deals)): - company = hubspot.from_deal_get_associated_company_id(deal) - if company in valueable_deals: - deals_to_add.append(deal) - deal_to_companies.update({deal: company}) - deal_data = hubspot.from_deal_get_info(deal_id=deal) - listing_data = hubspot.from_deal_get_associated_listing(deal_id=deal) - loader.new_record_to_hubspot_data(deal_data, deal_to_companies[deal], listing_data) +loader.new_record_company(company) diff --git a/etl/models/topLevel.py b/etl/models/topLevel.py index c803251..ba963a8 100644 --- a/etl/models/topLevel.py +++ b/etl/models/topLevel.py @@ -87,6 +87,28 @@ class HubspotDealData(SQLModel, table=True): ) ) + updated_at: Optional[datetime] = Field( + sa_column=Column(DateTime(timezone=True), nullable=True) + ) + +class HubspotCommpanyData(SQLModel, table=True): + __tablename__ = "hubspot_company_data" + + id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True) + + # HubSpot Deal identifiers + company_id: str = Field(index=True, nullable=False) + company_name: Optional[str] = Field(default=None) + group_id: Optional[str] = Field(default=None) + + created_at: datetime = Field( + sa_column=Column( + DateTime(timezone=True), + server_default=text("NOW() AT TIME ZONE 'utc'"), + nullable=False, + ) + ) + updated_at: Optional[datetime] = Field( sa_column=Column(DateTime(timezone=True), nullable=True) ) \ No newline at end of file diff --git a/migration_db.sh b/migration_db.sh index c36e69a..a65889a 100644 --- a/migration_db.sh +++ b/migration_db.sh @@ -1,4 +1,4 @@ -#poetry run alembic revision --autogenerate -m "added project code" +#poetry run alembic revision --autogenerate -m "add company info" poetry run alembic upgrade head