Download scripts/check_monetization.py from Mohansree/bsure-api: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/Mohansree/bsure-api/resolve/main/scripts/check_monetization.py
- Command line
-
hf download hf://spaces/Mohansree/bsure-api/scripts/check_monetization.py
-
curl -L -o check_monetization.py https://huggingface.co/spaces/Mohansree/bsure-api/resolve/main/scripts/check_monetization.py
1.73 kB
| import requests | |
| import json | |
| import time | |
| BASE_URL = "http://localhost:8000" | |
| def test_monetization(): | |
| print("Testing Monetization API...") | |
| # 1. Seed Data | |
| print("\n1. Seeding Data...") | |
| try: | |
| res = requests.post(f"{BASE_URL}/monetization/seed") | |
| print(res.json()) | |
| except Exception as e: | |
| print(f"❌ Seed failed: {e}") | |
| return | |
| # 2. Get Products | |
| print("\n2. Fetching Products...") | |
| products = [] | |
| try: | |
| res = requests.get(f"{BASE_URL}/monetization/products") | |
| products = res.json() | |
| print(f"✅ Found {len(products)} products") | |
| except Exception as e: | |
| print(f"❌ Fetch products failed: {e}") | |
| return | |
| if not products: | |
| print("❌ No products found, skipping click test") | |
| return | |
| # 3. Simulate Click | |
| target_id = products[0]['id'] | |
| print(f"\n3. Simulating Click on Product {target_id}...") | |
| try: | |
| res = requests.get(f"{BASE_URL}/monetization/redirect/{target_id}?user_id=1") | |
| data = res.json() | |
| print(f"✅ Redirect Info: {data}") | |
| if data['tracked']: | |
| print(" (Click tracked successfully)") | |
| except Exception as e: | |
| print(f"❌ Click tracking failed: {e}") | |
| # 4. Check Dashboard | |
| print("\n4. Checking Dashboard Stats...") | |
| try: | |
| res = requests.get(f"{BASE_URL}/monetization/dashboard") | |
| stats = res.json() | |
| print(f"✅ Total Revenue: ${stats['total_revenue']}") | |
| print(f"✅ Total Clicks: {stats['total_clicks']}") | |
| print(json.dumps(stats['brand_performance'], indent=2)) | |
| except Exception as e: | |
| print(f"❌ Dashboard stats failed: {e}") | |
| if __name__ == "__main__": | |
| test_monetization() | |