File size: 12,748 Bytes
a4a766c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# setup_sample_data.py
"""

🎯 Setup Sample Data for Campaign Trigger Testing

This script populates your Supabase database with sample campaigns and creators

so you can test the campaign trigger endpoints immediately.

"""

import asyncio
import logging
import uuid
from datetime import datetime, timedelta
from services.supabase_database import SupabaseDatabaseService

logger = logging.getLogger(__name__)

class SampleDataSetup:
    def __init__(self):
        self.db_service = SupabaseDatabaseService()
    
    async def setup_all_sample_data(self):
        """Setup all sample data for testing"""
        try:
            logger.info("πŸš€ Setting up sample data for campaign trigger testing...")
            
            # 1. Setup sample campaigns
            await self.setup_sample_campaigns()
            
            # 2. Setup sample creators
            await self.setup_sample_creators()
            
            logger.info("βœ… Sample data setup completed successfully!")
            return True
            
        except Exception as e:
            logger.error(f"❌ Sample data setup failed: {str(e)}")
            return False
    
    async def setup_sample_campaigns(self):
        """Setup sample campaigns in Supabase"""
        sample_campaigns = [
            {
                "id": "11111111-2222-3333-4444-555555555555",  # tech_campaign_001
                "product_name": "TechPro Wireless Earbuds",
                "brand_name": "AudioMax Technologies",
                "product_description": "Premium wireless earbuds with noise cancellation and superior sound quality for tech enthusiasts and professionals",
                "target_audience": "Tech enthusiasts, gamers, and professionals aged 20-40",
                "campaign_goal": "Launch new product and establish market presence in tech community",
                "product_niche": "tech",
                "total_budget": 15000.0,
                "status": "active",
                "sponsor_email": "sponsor@audiomax-tech.com",
                "sponsor_name": "Sarah Johnson",
                "sponsor_phone": "+1-555-0123",
                "sponsor_company": "AudioMax Technologies Inc.",
                "created_at": datetime.now().isoformat(),
                "updated_at": datetime.now().isoformat()
            },
            {
                "id": "22222222-3333-4444-5555-666666666666",  # fitness_campaign_002 
                "product_name": "FitPro Protein Powder",
                "brand_name": "LifeFit Nutrition",
                "product_description": "Premium whey protein powder for muscle building and recovery, perfect for serious athletes and fitness enthusiasts",
                "target_audience": "Fitness enthusiasts, gym-goers, and athletes aged 18-35",
                "campaign_goal": "Increase brand awareness and drive sales in the fitness community",
                "product_niche": "fitness",
                "total_budget": 12000.0,
                "status": "active",
                "sponsor_email": "marketing@lifefit-nutrition.com",
                "sponsor_name": "Mike Rodriguez",
                "sponsor_phone": "+1-555-0456",
                "sponsor_company": "LifeFit Nutrition Corp.",
                "created_at": (datetime.now() - timedelta(days=1)).isoformat(),
                "updated_at": datetime.now().isoformat()
            },
            {
                "id": "33333333-4444-5555-6666-777777777777",  # beauty_campaign_003
                "product_name": "GlowUp Skincare Set",
                "brand_name": "PureGlow Beauty",
                "product_description": "Complete skincare routine set with natural ingredients for healthy, glowing skin",
                "target_audience": "Beauty enthusiasts and skincare lovers aged 16-35",
                "campaign_goal": "Build brand awareness and drive online sales",
                "product_niche": "beauty",
                "total_budget": 18000.0,
                "status": "active",
                "sponsor_email": "campaigns@pureglow-beauty.com",
                "sponsor_name": "Emma Chen",
                "sponsor_phone": "+1-555-0789",
                "sponsor_company": "PureGlow Beauty LLC",
                "created_at": (datetime.now() - timedelta(days=2)).isoformat(),
                "updated_at": datetime.now().isoformat()
            }
        ]
        
        try:
            if not self.db_service.supabase:
                logger.warning("⚠️ Supabase not available - campaigns not created")
                return
            
            for campaign in sample_campaigns:
                # Check if campaign already exists
                existing = self.db_service.supabase.table("campaigns").select("id").eq("id", campaign["id"]).execute()
                
                if existing.data:
                    logger.info(f"πŸ“‹ Campaign {campaign['id']} already exists - updating...")
                    # Update existing campaign
                    self.db_service.supabase.table("campaigns").update(campaign).eq("id", campaign["id"]).execute()
                else:
                    logger.info(f"πŸ“‹ Creating campaign: {campaign['product_name']}")
                    # Insert new campaign
                    self.db_service.supabase.table("campaigns").insert(campaign).execute()
            
            logger.info(f"βœ… Setup {len(sample_campaigns)} sample campaigns")
            
        except Exception as e:
            logger.error(f"❌ Error setting up campaigns: {str(e)}")
            raise
    
    async def setup_sample_creators(self):
        """Setup sample creators in Supabase"""
        sample_creators = [
            {
                "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",  # creator_tech_001
                "name": "TechReviewer_Sarah",
                "email": "sarah.tech@example.com",
                "platform": "YouTube",
                "followers_count": "850K",
                "followers_count_numeric": 850000,
                "niche": "tech",
                "engagement_rate": 4.8,
                "phone_number": "+1-555-TECH-001"
            },
            {
                "id": "bbbbbbbb-cccc-dddd-eeee-ffffffffffff",  # creator_tech_002
                "name": "GadgetGuru_Alex",
                "email": "alex.gadgets@example.com",
                "platform": "YouTube",
                "followers_count": "1.2M",
                "followers_count_numeric": 1200000,
                "niche": "tech",
                "engagement_rate": 5.2,
                "phone_number": "+1-555-TECH-002"
            },
            {
                "id": "cccccccc-dddd-eeee-ffff-aaaaaaaaaaaa",  # creator_fitness_001
                "name": "FitnessGuru_Mike",
                "email": "mike.fitness@example.com",
                "platform": "Instagram",
                "followers_count": "650K",
                "followers_count_numeric": 650000,
                "niche": "fitness",
                "engagement_rate": 6.5,
                "phone_number": "+1-555-FIT-001"
            },
            {
                "id": "dddddddd-eeee-ffff-aaaa-bbbbbbbbbbbb",  # creator_fitness_002
                "name": "YogaLife_Emma",
                "email": "emma.yoga@example.com", 
                "platform": "Instagram",
                "followers_count": "420K",
                "followers_count_numeric": 420000,
                "niche": "fitness",
                "engagement_rate": 7.8,
                "phone_number": "+1-555-FIT-002"
            },
            {
                "id": "eeeeeeee-ffff-aaaa-bbbb-cccccccccccc",  # creator_beauty_001
                "name": "BeautyInfluencer_Priya",
                "email": "priya.beauty@example.com",
                "platform": "TikTok",
                "followers_count": "1.5M",
                "followers_count_numeric": 1500000,
                "niche": "beauty",
                "engagement_rate": 8.2,
                "phone_number": "+1-555-BEAUTY-001"
            },
            {
                "id": "ffffffff-aaaa-bbbb-cccc-dddddddddddd",  # creator_beauty_002
                "name": "SkinCareExpert_Lisa",
                "email": "lisa.skincare@example.com",
                "platform": "YouTube",
                "followers_count": "920K",
                "followers_count_numeric": 920000,
                "niche": "beauty",
                "engagement_rate": 5.9,
                "phone_number": "+1-555-BEAUTY-002"
            }
        ]
        
        try:
            if not self.db_service.supabase:
                logger.warning("⚠️ Supabase not available - creators not created")
                return
            
            for creator in sample_creators:
                # Check if creator already exists
                existing = self.db_service.supabase.table("creators").select("id").eq("id", creator["id"]).execute()
                
                if existing.data:
                    logger.info(f"πŸ‘€ Creator {creator['id']} already exists - updating...")
                    # Update existing creator
                    self.db_service.supabase.table("creators").update(creator).eq("id", creator["id"]).execute()
                else:
                    logger.info(f"πŸ‘€ Creating creator: {creator['name']}")
                    # Insert new creator
                    self.db_service.supabase.table("creators").insert(creator).execute()
            
            logger.info(f"βœ… Setup {len(sample_creators)} sample creators")
            
        except Exception as e:
            logger.error(f"❌ Error setting up creators: {str(e)}")
            raise
    
    async def verify_setup(self):
        """Verify that sample data was setup correctly"""
        try:
            if not self.db_service.supabase:
                logger.warning("⚠️ Supabase not available - cannot verify setup")
                return False
            
            # Check campaigns
            campaigns_result = self.db_service.supabase.table("campaigns").select("id, product_name, brand_name").execute()
            campaigns_count = len(campaigns_result.data) if campaigns_result.data else 0
            
            # Check creators  
            creators_result = self.db_service.supabase.table("creators").select("id, name, niche").execute()
            creators_count = len(creators_result.data) if creators_result.data else 0
            
            logger.info(f"πŸ“Š Database verification:")
            logger.info(f"   πŸ“‹ Campaigns: {campaigns_count}")
            logger.info(f"   πŸ‘€ Creators: {creators_count}")
            
            if campaigns_count >= 3 and creators_count >= 6:
                logger.info("βœ… Sample data setup verification successful!")
                return True
            else:
                logger.warning("⚠️ Sample data setup may be incomplete")
                return False
                
        except Exception as e:
            logger.error(f"❌ Setup verification failed: {str(e)}")
            return False

async def main():
    """Main function to run sample data setup"""
    setup = SampleDataSetup()
    
    print("πŸš€ Starting sample data setup for campaign trigger testing...")
    
    success = await setup.setup_all_sample_data()
    
    if success:
        print("\nπŸ“Š Verifying setup...")
        verified = await setup.verify_setup()
        
        if verified:
            print("\nβœ… Sample data setup completed successfully!")
            print("\n🎯 You can now test the campaign trigger endpoints:")
            print("   1. GET /api/campaign-trigger/campaigns - List available campaigns")
            print("   2. GET /api/campaign-trigger/discover/{campaign_id} - Preview creators for a campaign")
            print("   3. POST /api/campaign-trigger/trigger/{campaign_id} - Trigger AI calls")
            print("   4. GET /api/campaign-trigger/monitor/{task_id} - Monitor call progress")
            print("\nπŸ“‹ Sample campaign IDs:")
            print("   - tech_campaign_001 (TechPro Wireless Earbuds)")
            print("   - fitness_campaign_002 (FitPro Protein Powder)")
            print("   - beauty_campaign_003 (GlowUp Skincare Set)")
        else:
            print("\n⚠️ Setup completed but verification had issues")
    else:
        print("\n❌ Sample data setup failed")

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    asyncio.run(main())