mirror of
https://github.com/Hestia-Homes/insight.git
synced 2026-06-08 11:17:25 +00:00
Merge pull request #13 from Hestia-Homes/feature/forgot_to_branch_off
Feature/forgot to branch off
This commit is contained in:
commit
35f9473614
2 changed files with 63 additions and 14 deletions
|
|
@ -1,14 +1,53 @@
|
|||
#from dashboard.services.file_manager import FileManager
|
||||
#from dashboard.services.json_reader import jsonReader
|
||||
#s3 = FileManager()
|
||||
import asyncio
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
#key, path, data = s3.download_and_read_latest()
|
||||
#hubspot_data = jsonReader(data)
|
||||
from dashboard.services.hubspot_client import Pipeline
|
||||
from dashboard.services.hubspot_client_async import HubSpotClientAsync
|
||||
from dashboard.services.file_manager import FileManager
|
||||
|
||||
#df = hubspot_data.generate_df_via_product_type("Empty Cavity - ECO4")
|
||||
OUTPUT_FILE = "hubspot_deals.json"
|
||||
|
||||
|
||||
#one = df.iloc(0)
|
||||
async def main():
|
||||
hubspot = HubSpotClientAsync()
|
||||
|
||||
from dashboard.service
|
||||
# Fetch all deal IDs (but we will take only one)
|
||||
deals = await hubspot.get_deal_ids_by_pipeline(
|
||||
Pipeline.OPERATIONS_SOCIAL_HOUSING.value
|
||||
)
|
||||
|
||||
if not deals:
|
||||
print("No deals found.")
|
||||
return
|
||||
|
||||
# Only take ONE deal
|
||||
# Just do one
|
||||
deal_id = deals[0]
|
||||
print(f"Fetching only deal: {deal_id}")
|
||||
|
||||
try:
|
||||
data = await hubspot.from_deal_get_info(deal_id)
|
||||
except Exception as e:
|
||||
print(f"Error fetching deal {deal_id}: {e}")
|
||||
return
|
||||
|
||||
# Save result
|
||||
with open(OUTPUT_FILE, "w") as f:
|
||||
json.dump([data], f, indent=2)
|
||||
|
||||
print("Done! Saved 1 deal.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
fm = FileManager()
|
||||
timestamp = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
|
||||
s3_filename = f"hubspot_deals_{timestamp}.json"
|
||||
|
||||
fm.upload_to_s3(
|
||||
OUTPUT_FILE,
|
||||
bucket="retrofit-data-dev",
|
||||
object_name=f"hubspot_insight/{s3_filename}"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import logging
|
|||
import asyncio
|
||||
from hubspot.crm.associations import ApiException
|
||||
import hubspot
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class HubSpotClientAsync:
|
||||
API_CONCURRENCY = asyncio.Semaphore(5) # globally limit concurrency
|
||||
|
|
@ -135,9 +137,7 @@ class HubSpotClientAsync:
|
|||
company_id = await self.from_deal_get_associated_company_id(deal_id)
|
||||
company_info = await self.get_company_information(company_id) if company_id else {}
|
||||
appointments = await self.from_deal_get_appointments(deal_id)
|
||||
|
||||
|
||||
|
||||
|
||||
return {
|
||||
"deal_properties": deal_info,
|
||||
"line_items": line_items,
|
||||
|
|
@ -298,7 +298,7 @@ class HubSpotClientAsync:
|
|||
return results
|
||||
|
||||
async def get_expected_commencement_history(self, deal_id: str):
|
||||
"""Fetch historical values for expected_commencement_date."""
|
||||
"""Fetch JSON-serializable historical values for expected_commencement_date."""
|
||||
deal = await self._run(
|
||||
self.client.crm.deals.basic_api.get_by_id,
|
||||
deal_id,
|
||||
|
|
@ -306,6 +306,16 @@ class HubSpotClientAsync:
|
|||
properties_with_history=["expected_commencement_date"]
|
||||
)
|
||||
|
||||
return deal.properties_with_history.get("expected_commencement_date", [])
|
||||
|
||||
history = deal.properties_with_history.get("expected_commencement_date", [])
|
||||
|
||||
json_ready_history = []
|
||||
for entry in history:
|
||||
safe_entry = {}
|
||||
for key, val in entry.to_dict().items():
|
||||
if isinstance(val, datetime):
|
||||
safe_entry[key] = val.isoformat()
|
||||
else:
|
||||
safe_entry[key] = val
|
||||
json_ready_history.append(safe_entry)
|
||||
|
||||
return json_ready_history
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue