Spaces:
Configuration error
Configuration error
| #!/usr/bin/env python3 | |
| """ | |
| Generate API key for Castor Forecasting API | |
| """ | |
| import requests | |
| import json | |
| import sys | |
| import time | |
| # Wait for server to be ready | |
| time.sleep(3) | |
| try: | |
| url = "http://127.0.0.1:5000/api/keys/generate" | |
| headers = {"Content-Type": "application/json"} | |
| data = {"name": "app_developer"} | |
| print("Generating API key...") | |
| response = requests.post(url, json=data, headers=headers, timeout=5) | |
| if response.status_code == 200: | |
| result = response.json() | |
| print("\n✅ API Key Generated Successfully!") | |
| print("\n" + "="*60) | |
| print(f"API Key: {result.get('api_key')}") | |
| print(f"Name: {result.get('name')}") | |
| print(f"Created: {result.get('created_at')}") | |
| print("="*60) | |
| # Save to file | |
| with open('API_KEY.txt', 'w') as f: | |
| f.write(f"API Key: {result.get('api_key')}\n") | |
| f.write(f"Name: {result.get('name')}\n") | |
| f.write(f"Created: {result.get('created_at')}\n") | |
| f.write(f"\nAPI Server URL: http://127.0.0.1:5000\n") | |
| f.write(f"Use this key in X-API-Key header for all requests\n") | |
| print("\n✅ API Key saved to API_KEY.txt") | |
| else: | |
| print(f"Error: {response.status_code}") | |
| print(response.text) | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| sys.exit(1) | |