mirror of
https://github.com/Hestia-Homes/survey-extraction.git
synced 2026-06-30 13:10:56 +00:00
87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
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.ABRI,
|
||
Companies.LIVEWEST,
|
||
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 (don’t 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")
|