PGC-AI-Chatbot / scripts /sync_plants_from_supabase.py
Jacooo's picture
Deploy from GitHub: ca4460e
1f53415 verified
"""
Supabase → plants_database.json Sync Script
=============================================
Standalone script to re-import the verified plant growth parameters
from the Supabase cloud database into the local JSON file.
This file is the "structured data" source for JSON Routing in the
AI Chatbot pipeline. It contains quantitative parameters (temperature,
humidity, light) for 21+ plants across all lifecycle stages.
Usage:
cd "c:\\Users\\justi\\Jac ITB\\TA PGC Smartness\\AI Chatbot"
python scripts/sync_plants_from_supabase.py
"""
import asyncio
import sys
from pathlib import Path
# Add the project root to sys.path so we can import from app/
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
from app.supabase_client import sync_from_cloud, is_configured
async def main():
print("=" * 55)
print(" PGC Supabase -> plants_database_day_night.json Sync")
print("=" * 55)
if not is_configured():
print("\n[ERROR] SUPABASE_URL and SUPABASE_KEY not set in .env")
print(" Please configure your .env file first.")
return
print("\n[...] Fetching plants from Supabase cloud...")
result = await sync_from_cloud()
if result.success:
print(f"\n[OK] SUCCESS: {result.plants_synced} plants synced")
print(f" Timestamp: {result.timestamp}")
print(f" File: data/plants_database_day_night.json")
else:
print(f"\n[FAIL] {result.message}")
if result.errors:
for error in result.errors:
print(f" - {error}")
if result.errors and result.success:
print("\n[WARN] Warnings:")
for error in result.errors:
print(f" - {error}")
print()
if __name__ == "__main__":
asyncio.run(main())