Spaces:
Running
Running
File size: 2,215 Bytes
3615850 de146fb 3615850 de146fb 3615850 de146fb 3615850 de146fb 3615850 de146fb 3615850 a556bfd 3615850 a556bfd 8995f83 3615850 a556bfd 3615850 a556bfd 1cb51f8 3615850 a556bfd 3615850 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# services/report_data_handler.py
import pandas as pd
import logging
from apis.Bubble_API_Calls import fetch_linkedin_posts_data_from_bubble, bulk_upload_to_bubble
from config import (
BUBBLE_REPORT_TABLE_NAME,
BUBBLE_OKR_TABLE_NAME,
BUBBLE_KEY_RESULTS_TABLE_NAME,
BUBBLE_TASKS_TABLE_NAME,
BUBBLE_KR_UPDATE_TABLE_NAME,
)
import json # For handling JSON data
logger = logging.getLogger(__name__)
def fetch_latest_agentic_analysis(org_urn: str):
"""
Fetches all agentic analysis data for a given org_urn from Bubble.
Returns the full dataframe and any error, or None, None.
"""
if not org_urn:
logger.warning("fetch_latest_agentic_analysis: org_urn is missing.")
return None, None
report_data_df, error = fetch_linkedin_posts_data_from_bubble(
data_type=BUBBLE_REPORT_TABLE_NAME,
org_urn=org_urn
)
if error or report_data_df is None or report_data_df.empty:
logger.info(f"No existing agentic analysis found in Bubble for org_urn {org_urn} or error: {error}")
return None, None
logger.info(f"Agentic analysis data fetched for org_urn {org_urn}")
return report_data_df, None # Return full dataframe and no error
def save_report_results(
org_urn: str,
report_markdown: str,
quarter,
year,
report_type: str,
):
"""Saves the agentic pipeline results to Bubble."""
if not org_urn:
logger.error("Cannot save agentic results: org_urn missing.")
return False
payload = {
"organization_urn": org_urn,
"report_markdown": report_markdown if report_markdown else "N/A",
"quarter": quarter,
"year": year,
"report_type": report_type,
}
logger.info(f"Attempting to save agentic analysis to Bubble for org_urn: {org_urn}")
success_ids = bulk_upload_to_bubble([payload], BUBBLE_REPORT_TABLE_NAME)
if success_ids and success_ids[0]: # bulk_upload_to_bubble returns list of IDs or False
logger.info(f"Successfully saved agentic analysis to Bubble. Record ID: {success_ids[0]}")
return True
else:
logger.error("Failed to save agentic analysis to Bubble.")
return False |