survey-extraction/etl/hubSpotClient/scripts/hubspot_update_script.py

86 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from etl.hubSpotClient.hubspotClient import HubSpotClient, Companies, Pipeline
from tqdm import tqdm
from etl.db.hubSpotLoad import HubspotTodb
hubspot = HubSpotClient()
hubspot.get_deal_stages()
db = HubspotTodb()
companies = [
Companies.THE_GUINESS_PARTNERSHIP,
Companies.SOUTHERN_HOUSING_GROUP,
]
# Global trackers
all_failed_deals = []
summary_report = {}
print("\n🚀 Starting HubSpot deal consistency check...\n")
for company in companies:
print(f"\n🏢 Processing company: {company.name}")
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
print(f"🧩 Deal {deal} was updated.")
else:
print(f"📈 Deal {deal} already up to date.")
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 per-company summary (dont print yet)
summary_report[company.name] = {
"checked": checked_count,
"updated": updated_count,
"failed": len(failed_deals),
"up_to_date": checked_count - updated_count - len(failed_deals),
}
# Company-level quick summary
print(f"\n✅ Finished checking {checked_count} deals for company {company.name}.")
print(f" 🧩 {updated_count} deal(s) were updated.")
print(f" 📈 {summary_report[company.name]['up_to_date']} deal(s) were already up to date.")
print(f" ⚠️ {len(failed_deals)} deal(s) failed.\n")
# ---- Final Summary Report ----
print("\n" + "=" * 100)
print("📊 FINAL SUMMARY REPORT (ALL COMPANIES)")
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 Failed Deals ----
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!")
print("\n🏁 HubSpot deal consistency check complete!\n")