niwayandm commited on
Commit
a2f1dfd
·
1 Parent(s): 0b0141b

Added several properties to companies, contacts, deals, and tickets

Browse files
python/hubspot_companies.py CHANGED
@@ -82,6 +82,14 @@ COMPANY_PROPERTIES = [
82
  "industry",
83
  "macro_industry_grouping",
84
  "closest_review_date___clone",
 
 
 
 
 
 
 
 
85
  ]
86
 
87
  # -----------------------------------------------------------------------------
@@ -222,6 +230,7 @@ def _enrich_company_data_from_record(
222
  record,
223
  industry_map: Dict[str, str],
224
  macro_industry_map: Dict[str, str],
 
225
  ) -> Dict:
226
  props = record.properties or {}
227
  company_data: Dict[str, Optional[str]] = {"id": record.id}
@@ -249,6 +258,10 @@ def _enrich_company_data_from_record(
249
  macro = company_data.get("macro_industry_grouping")
250
  company_data["macro_industry_grouping"] = macro_industry_map.get(
251
  macro) if macro in macro_industry_map else None
 
 
 
 
252
 
253
  return company_data
254
 
@@ -275,6 +288,13 @@ def read_companies_by_ids(company_ids: List[str], cursor_prop: str) -> Tuple[Lis
275
  logging.warning("Failed to fetch macro_industry_grouping map: %s", e)
276
  macro_industry_map = {}
277
 
 
 
 
 
 
 
 
278
  max_ts_ms: Optional[int] = None
279
 
280
  for i, cid in enumerate(company_ids, start=1):
@@ -293,7 +313,7 @@ def read_companies_by_ids(company_ids: List[str], cursor_prop: str) -> Tuple[Lis
293
  max_ts_ms = ts_ms
294
 
295
  companies.append(_enrich_company_data_from_record(
296
- record, industry_map, macro_industry_map))
297
 
298
  if i % 200 == 0:
299
  logging.info("Read %d companies...", i)
@@ -333,6 +353,14 @@ def map_company_data_for_db(companies: List[Dict]) -> List[Dict]:
333
  "industry": c.get("industry"),
334
  "macro_industry_grouping": c.get("macro_industry_grouping"),
335
  "closest_review_date": parse_ts(c.get("closest_review_date___clone")),
 
 
 
 
 
 
 
 
336
  }
337
  mapped.append(enrich_supabase_row(base_row))
338
  return mapped
@@ -345,6 +373,9 @@ def companies_are_different(new_row: Dict, old_row: Dict) -> bool:
345
  "number_of_active_clis", "number_of_clis",
346
  "number_of_associated_contacts", "number_of_associated_deals",
347
  "industry", "macro_industry_grouping", "closest_review_date",
 
 
 
348
  ]
349
  for key in compare_keys:
350
  if str(new_row.get(key)) != str(old_row.get(key)):
 
82
  "industry",
83
  "macro_industry_grouping",
84
  "closest_review_date___clone",
85
+ "region",
86
+ "industry_grouping",
87
+ "source_1",
88
+ "source_2",
89
+ "hs_object_source_label",
90
+ "hs_analytics_source",
91
+ "hs_analytics_latest_source",
92
+ "hs_object_source_detail_1",
93
  ]
94
 
95
  # -----------------------------------------------------------------------------
 
230
  record,
231
  industry_map: Dict[str, str],
232
  macro_industry_map: Dict[str, str],
233
+ region_map: Dict[str, str],
234
  ) -> Dict:
235
  props = record.properties or {}
236
  company_data: Dict[str, Optional[str]] = {"id": record.id}
 
258
  macro = company_data.get("macro_industry_grouping")
259
  company_data["macro_industry_grouping"] = macro_industry_map.get(
260
  macro) if macro in macro_industry_map else None
261
+
262
+ region = company_data.get("region")
263
+ company_data["region"] = region_map.get(
264
+ region) if region in region_map else None
265
 
266
  return company_data
267
 
 
288
  logging.warning("Failed to fetch macro_industry_grouping map: %s", e)
289
  macro_industry_map = {}
290
 
291
+ try:
292
+ region_map = get_property_label_mapping(
293
+ hubspot_client, "companies", "region")
294
+ except Exception as e:
295
+ logging.warning("Failed to fetch region map: %s", e)
296
+ region_map = {}
297
+
298
  max_ts_ms: Optional[int] = None
299
 
300
  for i, cid in enumerate(company_ids, start=1):
 
313
  max_ts_ms = ts_ms
314
 
315
  companies.append(_enrich_company_data_from_record(
316
+ record, industry_map, macro_industry_map, region_map))
317
 
318
  if i % 200 == 0:
319
  logging.info("Read %d companies...", i)
 
353
  "industry": c.get("industry"),
354
  "macro_industry_grouping": c.get("macro_industry_grouping"),
355
  "closest_review_date": parse_ts(c.get("closest_review_date___clone")),
356
+ "region": c.get(c.get("region")),
357
+ "closest_review_date": parse_ts(c.get("closest_review_date___clone")),
358
+ "source_1": c.get("source_1"),
359
+ "source_2": c.get("source_2"),
360
+ "record_source": c.get("hs_object_source_label"),
361
+ "record_source_detail_1": c.get("hs_object_source_detail_1"),
362
+ "original_traffic_source": c.get("hs_analytics_source"),
363
+ "latest_traffic_source": c.get("hs_analytics_latest_source"),
364
  }
365
  mapped.append(enrich_supabase_row(base_row))
366
  return mapped
 
373
  "number_of_active_clis", "number_of_clis",
374
  "number_of_associated_contacts", "number_of_associated_deals",
375
  "industry", "macro_industry_grouping", "closest_review_date",
376
+ "region", "source_1", "source_2", "record_source",
377
+ "record_source_detail_1", "original_traffic_source",
378
+ "latest_traffic_source",
379
  ]
380
  for key in compare_keys:
381
  if str(new_row.get(key)) != str(old_row.get(key)):
python/hubspot_contacts.py CHANGED
@@ -70,6 +70,13 @@ CONTACT_PROPERTIES = [
70
  "hs_lastmodifieddate",
71
  "notes_last_updated",
72
  "associatedcompanyid",
 
 
 
 
 
 
 
73
  ]
74
 
75
  # -----------------------------------------------------------------------------
@@ -137,6 +144,12 @@ def map_contact_data_for_db(contacts: List[Dict]) -> List[Dict]:
137
  "hubspot_last_activity_date": parse_ts(c.get("notes_last_updated")) or None,
138
  "number_of_associated_deals": c.get("number_of_associated_deals", 0),
139
  "associated_company_id": try_parse_int(c.get("associatedcompanyid")),
 
 
 
 
 
 
140
  }
141
  mapped.append(enrich_supabase_row(base_row))
142
  return mapped
@@ -146,7 +159,9 @@ def contacts_are_different(new_row: Dict, old_row: Dict) -> bool:
146
  "full_name", "first_name", "last_name", "email", "phone_number",
147
  "hubspot_create_date", "hubspot_modified_date",
148
  "hubspot_last_activity_date", "number_of_associated_deals",
149
- "associated_company_id"
 
 
150
  ]
151
  for key in compare_keys:
152
  if str(new_row.get(key)) != str(old_row.get(key)):
 
70
  "hs_lastmodifieddate",
71
  "notes_last_updated",
72
  "associatedcompanyid",
73
+ "jobtitle",
74
+ "hs_object_source_label",
75
+ "source_1__cont_",
76
+ "source_2",
77
+ "hs_object_source_detail_1",
78
+ "hs_analytics_source",
79
+ "hs_latest_source",
80
  ]
81
 
82
  # -----------------------------------------------------------------------------
 
144
  "hubspot_last_activity_date": parse_ts(c.get("notes_last_updated")) or None,
145
  "number_of_associated_deals": c.get("number_of_associated_deals", 0),
146
  "associated_company_id": try_parse_int(c.get("associatedcompanyid")),
147
+ "record_source": c.get("hs_object_source_label"),
148
+ "source_1": c.get("source_1__cont_"),
149
+ "source_2": c.get("source_2"),
150
+ "record_source_detail_1": c.get("hs_object_source_detail_1"),
151
+ "original_traffic_source": c.get("hs_analytics_source"),
152
+ "latest_traffic_source": c.get("hs_latest_source"),
153
  }
154
  mapped.append(enrich_supabase_row(base_row))
155
  return mapped
 
159
  "full_name", "first_name", "last_name", "email", "phone_number",
160
  "hubspot_create_date", "hubspot_modified_date",
161
  "hubspot_last_activity_date", "number_of_associated_deals",
162
+ "associated_company_id", "record_source", "source_1", "source_2",
163
+ "record_source_detail_1", "original_traffic_source",
164
+ "latest_traffic_source",
165
  ]
166
  for key in compare_keys:
167
  if str(new_row.get(key)) != str(old_row.get(key)):
python/hubspot_deals.py CHANGED
@@ -68,6 +68,9 @@ DEAL_PROPERTIES = [
68
  "margin",
69
  "source_of_deal_2___migration",
70
  "hs_primary_associated_company",
 
 
 
71
  "hs_lastmodifieddate", # for mapping/debugging
72
  "lastmodifieddate",
73
  ]
@@ -329,6 +332,9 @@ def read_deals_by_ids(
329
  "total_contract_value": try_parse_float(p.get("hs_tcv")),
330
  "margin": try_parse_float(p.get("margin")),
331
  "source_of_deal": p.get("source_of_deal_2___migration"),
 
 
 
332
  "company_id": company_id,
333
  })
334
 
 
68
  "margin",
69
  "source_of_deal_2___migration",
70
  "hs_primary_associated_company",
71
+ "hs_object_source_label",
72
+ "hs_object_source_detail_1",
73
+ "dealtype",
74
  "hs_lastmodifieddate", # for mapping/debugging
75
  "lastmodifieddate",
76
  ]
 
332
  "total_contract_value": try_parse_float(p.get("hs_tcv")),
333
  "margin": try_parse_float(p.get("margin")),
334
  "source_of_deal": p.get("source_of_deal_2___migration"),
335
+ "record_source": p.get("hs_object_source_label"),
336
+ "record_source_detail_1": p.get("hs_object_source_detail_1"),
337
+ "dealtype": p.get("dealtype"),
338
  "company_id": company_id,
339
  })
340
 
python/hubspot_tickets.py CHANGED
@@ -83,6 +83,8 @@ TICKET_PROPERTIES = [
83
  "subject",
84
  "hubspot_owner_id",
85
  "source_type",
 
 
86
  ]
87
 
88
  # -----------------------------------------------------------------------------
@@ -294,7 +296,9 @@ def read_tickets_by_ids(
294
  "ticket_status_id": try_parse_int(p.get("hs_pipeline_stage")),
295
  "ticket_status_label": stage_map.get(p.get("hs_pipeline_stage"), ""),
296
  "ticket_priority": p.get("hs_ticket_priority"),
297
- "source_type": p.get("source_type"),
 
 
298
  "hubspot_owner_id": try_parse_int(p.get("hubspot_owner_id")),
299
  "hubspot_created_at": parse_ts(p.get("createdate")),
300
  "hubspot_created_by": try_parse_int(p.get("hs_created_by_user_id")),
 
83
  "subject",
84
  "hubspot_owner_id",
85
  "source_type",
86
+ "hs_object_source_label",
87
+ "hs_object_source_detail_1",
88
  ]
89
 
90
  # -----------------------------------------------------------------------------
 
296
  "ticket_status_id": try_parse_int(p.get("hs_pipeline_stage")),
297
  "ticket_status_label": stage_map.get(p.get("hs_pipeline_stage"), ""),
298
  "ticket_priority": p.get("hs_ticket_priority"),
299
+ "source": p.get("source_type"),
300
+ "record_source": p.get("hs_object_source_label"),
301
+ "record_source_detail_1": p.get("hs_object_source_detail_1"),
302
  "hubspot_owner_id": try_parse_int(p.get("hubspot_owner_id")),
303
  "hubspot_created_at": parse_ts(p.get("createdate")),
304
  "hubspot_created_by": try_parse_int(p.get("hs_created_by_user_id")),