fix(explorer): resolve notion sync, add debug logging, and fix UI display for industries v0.6.1
This commit is contained in:
@@ -11,7 +11,7 @@ from backend.database import SessionLocal, Industry, RoboticsCategory, init_db
|
||||
from backend.config import settings
|
||||
|
||||
# Setup Logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
NOTION_TOKEN_FILE = "/app/notion_token.txt"
|
||||
@@ -71,6 +71,9 @@ def extract_number(prop):
|
||||
|
||||
def sync_categories(token, session):
|
||||
logger.info("Syncing Robotics Categories...")
|
||||
# session.query(RoboticsCategory).delete() # DANGEROUS - Reverted to Upsert
|
||||
# session.commit()
|
||||
|
||||
pages = query_notion_db(token, CATEGORIES_DB_ID)
|
||||
|
||||
count = 0
|
||||
@@ -98,16 +101,19 @@ def sync_categories(token, session):
|
||||
|
||||
cat.name = name
|
||||
cat.description = description
|
||||
# cat.reasoning_guide = ... ? Maybe 'Constrains'?
|
||||
cat.reasoning_guide = extract_rich_text(props.get("Constrains"))
|
||||
|
||||
count += 1
|
||||
|
||||
session.commit()
|
||||
logger.info(f"Synced {count} categories.")
|
||||
logger.info(f"Synced (Upsert) {count} categories.")
|
||||
|
||||
def sync_industries(token, session):
|
||||
logger.info("Syncing Industries...")
|
||||
logger.warning("DELETING all existing industries before sync...")
|
||||
session.query(Industry).delete()
|
||||
session.commit()
|
||||
|
||||
pages = query_notion_db(token, INDUSTRIES_DB_ID)
|
||||
|
||||
count = 0
|
||||
@@ -115,21 +121,17 @@ def sync_industries(token, session):
|
||||
props = page.get("properties", {})
|
||||
|
||||
notion_id = page["id"]
|
||||
name = extract_title(props.get("Industry"))
|
||||
# In Notion, the column is now 'Vertical' not 'Industry'
|
||||
name = extract_title(props.get("Vertical"))
|
||||
if not name: continue
|
||||
|
||||
# Upsert Logic: Check ID -> Check Name -> Create
|
||||
industry = session.query(Industry).filter(Industry.notion_id == notion_id).first()
|
||||
if not industry:
|
||||
industry = session.query(Industry).filter(Industry.name == name).first()
|
||||
if industry:
|
||||
logger.info(f"Linked existing industry '{name}' to Notion ID {notion_id}")
|
||||
industry.notion_id = notion_id
|
||||
else:
|
||||
industry = Industry(notion_id=notion_id, name=name)
|
||||
session.add(industry)
|
||||
# Removed full Notion props debug log - no longer needed
|
||||
|
||||
# Logic is now INSERT only
|
||||
industry = Industry(notion_id=notion_id, name=name)
|
||||
session.add(industry)
|
||||
|
||||
# Map Fields
|
||||
# Map Fields from Notion Schema
|
||||
industry.name = name
|
||||
industry.description = extract_rich_text(props.get("Definition"))
|
||||
|
||||
@@ -137,18 +139,19 @@ def sync_industries(token, session):
|
||||
industry.status_notion = status
|
||||
industry.is_focus = (status == "P1 Focus Industry")
|
||||
|
||||
industry.industry_group = extract_rich_text(props.get("Industry-Group"))
|
||||
industry.whale_threshold = extract_number(props.get("Whale Threshold"))
|
||||
# New Schema Fields
|
||||
industry.metric_type = extract_select(props.get("Metric Type"))
|
||||
industry.min_requirement = extract_number(props.get("Min. Requirement"))
|
||||
industry.whale_threshold = extract_number(props.get("Whale Threshold"))
|
||||
industry.proxy_factor = extract_number(props.get("Proxy Factor"))
|
||||
industry.scraper_search_term = extract_select(props.get("Scraper Search Term")) # <-- FIXED HERE
|
||||
industry.scraper_keywords = extract_rich_text(props.get("Scraper Keywords"))
|
||||
industry.core_unit = extract_select(props.get("Core Unit"))
|
||||
industry.proxy_factor = extract_rich_text(props.get("Proxy Factor"))
|
||||
|
||||
industry.standardization_logic = extract_rich_text(props.get("Stanardization Logic"))
|
||||
|
||||
# Relation: Primary Product Category
|
||||
relation = props.get("Primary Product Category", {}).get("relation", [])
|
||||
if relation:
|
||||
related_id = relation[0]["id"]
|
||||
# Find Category by notion_id
|
||||
cat = session.query(RoboticsCategory).filter(RoboticsCategory.notion_id == related_id).first()
|
||||
if cat:
|
||||
industry.primary_category_id = cat.id
|
||||
@@ -173,4 +176,4 @@ if __name__ == "__main__":
|
||||
except Exception as e:
|
||||
logger.error(f"Sync failed: {e}", exc_info=True)
|
||||
finally:
|
||||
db.close()
|
||||
db.close()
|
||||
Reference in New Issue
Block a user