mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-30 13:10:56 +00:00
save
This commit is contained in:
parent
702d13542d
commit
15af734289
5 changed files with 47 additions and 32 deletions
|
|
@ -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
|
||||
|
|
@ -124,4 +124,13 @@ class HubSpotClient():
|
|||
)
|
||||
|
||||
return deal.properties
|
||||
|
||||
|
||||
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
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
)
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue