mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-30 13:10:56 +00:00
Merge pull request #118 from Hestia-Homes/feature/sureurve
Feature/sureurve
This commit is contained in:
commit
b1fa9cc7a0
7 changed files with 49 additions and 74 deletions
10
.github/workflows/hubspot_sync.yml
vendored
10
.github/workflows/hubspot_sync.yml
vendored
|
|
@ -21,6 +21,16 @@ jobs:
|
|||
pip install poetry
|
||||
poetry install --no-root
|
||||
|
||||
- name: Run scripts
|
||||
env:
|
||||
PYTHONPATH: ${{ github.workspace }}
|
||||
DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}
|
||||
run: |
|
||||
pwd
|
||||
ls -la
|
||||
poetry run python etl/hubSpotClient/scripts/hubspot_abri_etl_first_time.py
|
||||
|
||||
|
||||
- name: Run scripts
|
||||
env:
|
||||
PYTHONPATH: ${{ github.workspace }}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ class HubspotTodb:
|
|||
init_db()
|
||||
self.s3 = S3Uploader()
|
||||
|
||||
def new_record_to_hubspot_data(self, deal_data, company, listing):
|
||||
def new_record_to_hubspot_data(self, deal_data, company, listing, hubspot_client):
|
||||
print("⚠️ Deprecated — use the new interface instead.")
|
||||
return self.upsert_hubspot_deal(deal_data, company, listing)
|
||||
return self.upsert_hubspot_deal(deal_data, company, listing, hubspot_client)
|
||||
|
||||
def new_record_company(self, company_data):
|
||||
"""Adds a new record to the hubspot_company_data table."""
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Companies(Enum):
|
|||
ABRI = "237615001799"
|
||||
SOUTHERN_HOUSING_GROUP = "109343619305"
|
||||
LIVEWEST = "86205872354"
|
||||
SURESERVE = "301745289413"
|
||||
|
||||
class DealStage(Enum):
|
||||
SURVEYED_COMPLETE_NEEDS_SIGN_OFF = "1617223914"
|
||||
|
|
|
|||
|
|
@ -2,72 +2,32 @@ from etl.hubSpotClient.hubspotClient import HubSpotClient, Companies, Pipeline
|
|||
from tqdm import tqdm
|
||||
from etl.db.hubSpotLoad import HubspotTodb
|
||||
|
||||
# get ALL deals
|
||||
hubspot = HubSpotClient()
|
||||
hubspot.get_deal_stages()
|
||||
db = HubspotTodb()
|
||||
|
||||
companies = [
|
||||
Companies.ABRI,
|
||||
Companies.LIVEWEST,
|
||||
Companies.SOUTHERN_HOUSING_GROUP,
|
||||
# All deals from a pipeline_id via filter
|
||||
deals = hubspot.get_deal_ids_by_pipeline(
|
||||
pipeline_id=Pipeline.OPERATIONS_SOCIAL_HOUSING.value,
|
||||
)
|
||||
|
||||
# deals from companies we care about
|
||||
valueable_deals = [
|
||||
Companies.ABRI.value,
|
||||
Companies.SOUTHERN_HOUSING_GROUP.value,
|
||||
Companies.SURESERVE.value,
|
||||
Companies.LIVEWEST.value,
|
||||
]
|
||||
deals_to_add = []
|
||||
|
||||
# Track all failures and summary data
|
||||
all_failed_deals = []
|
||||
summary_report = {}
|
||||
|
||||
for company in companies:
|
||||
records = db.find_all_deals_with_company_id(company.value)
|
||||
|
||||
updated_count = 0
|
||||
checked_count = 0
|
||||
failed_deals = []
|
||||
|
||||
for deal in tqdm(records, desc=f"Checking HubSpot deals for {company.name}"):
|
||||
checked_count += 1
|
||||
try:
|
||||
print(f"🔍 Working on deal {deal}")
|
||||
was_up_to_date = db.update_deal(deal, hubspot)
|
||||
|
||||
if not was_up_to_date:
|
||||
updated_count += 1
|
||||
|
||||
except Exception as e:
|
||||
failed_info = {
|
||||
"company": company.name,
|
||||
"deal_id": deal,
|
||||
"error": str(e)
|
||||
}
|
||||
failed_deals.append(failed_info)
|
||||
all_failed_deals.append(failed_info)
|
||||
print(f"❌ Failed to update deal {deal}: {e}")
|
||||
|
||||
# Store company-level summary (don’t print yet)
|
||||
summary_report[company.name] = {
|
||||
"checked": checked_count,
|
||||
"updated": updated_count,
|
||||
"up_to_date": checked_count - updated_count - len(failed_deals),
|
||||
"failed": len(failed_deals),
|
||||
}
|
||||
|
||||
# ---- Final Summary Report ----
|
||||
print("\n" + "="*100)
|
||||
print("📊 FINAL SUMMARY REPORT")
|
||||
print("="*100)
|
||||
|
||||
for company_name, stats in summary_report.items():
|
||||
print(f"\n🏢 {company_name}")
|
||||
print(f" - Total deals checked: {stats['checked']}")
|
||||
print(f" - Updated deals: {stats['updated']}")
|
||||
print(f" - Up-to-date deals: {stats['up_to_date']}")
|
||||
print(f" - Failed deals: {stats['failed']}")
|
||||
|
||||
# ---- Global failure details ----
|
||||
if all_failed_deals:
|
||||
print("\n" + "="*100)
|
||||
print("⚠️ FAILED DEALS DETAILS")
|
||||
print("="*100)
|
||||
for f in all_failed_deals:
|
||||
print(f" - Company: {f['company']:<25} | Deal ID: {f['deal_id']} | Error: {f['error']}")
|
||||
else:
|
||||
print("\n🎉 No failed deals across any company!")
|
||||
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, hubspot)
|
||||
|
|
@ -4,12 +4,15 @@ from etl.db.hubSpotLoad import HubspotTodb
|
|||
|
||||
hubspot = HubSpotClient()
|
||||
|
||||
companies = [
|
||||
Companies.ABRI,
|
||||
Companies.LIVEWEST,
|
||||
Companies.SOUTHERN_HOUSING_GROUP,
|
||||
Companies.SURESERVE,
|
||||
]
|
||||
# All deals from a pipeline_id via filter
|
||||
company = hubspot.get_company_information(Companies.SOUTHERN_HOUSING_GROUP.value)
|
||||
|
||||
loader = HubspotTodb()
|
||||
loader.new_record_company(company)
|
||||
|
||||
|
||||
# make a scrip that updates table, with khalim scoping
|
||||
|
||||
for comapny in companies:
|
||||
new_company_info = hubspot.get_company_information(company.value)
|
||||
loader = HubspotTodb()
|
||||
loader.new_record_company(new_company_info)
|
||||
|
|
@ -10,6 +10,7 @@ companies = [
|
|||
Companies.ABRI,
|
||||
Companies.LIVEWEST,
|
||||
Companies.SOUTHERN_HOUSING_GROUP,
|
||||
Companies.SURESERVE,
|
||||
]
|
||||
|
||||
# Global trackers
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
# Example of how to run python code in this environment
|
||||
poetry run python etl/daily_script.py --debug
|
||||
poetry run python etl/hubSpotClient/scripts/hubspot_abri_etl_first_time.py --debug
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue