File size: 1,792 Bytes
330dc8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f53415
330dc8c
 
 
 
 
 
 
 
 
 
 
 
 
1f53415
330dc8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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())