Spaces:
Running
Running
Download test_api.py from sisithefox/astrology-ziwei-api: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/sisithefox/astrology-ziwei-api/resolve/main/test_api.py
- Command line
-
hf download hf://spaces/sisithefox/astrology-ziwei-api/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/sisithefox/astrology-ziwei-api/resolve/main/test_api.py
1.6 kB
| #!/usr/bin/env python3 | |
| """ | |
| 🧪 Test Ziwei API locally | |
| """ | |
| import requests | |
| import json | |
| # Test data | |
| test_request = { | |
| "birth_date": "2000-1-1", | |
| "birth_time": "14:30", | |
| "gender": "男", | |
| "is_leap_month": False, | |
| "fix_leap": True | |
| } | |
| print("🔮 Testing Ziwei API...") | |
| print(f"Request: {json.dumps(test_request, ensure_ascii=False)}\n") | |
| try: | |
| # Note: This test requires the API to be running | |
| # Run: uvicorn app:app --host 127.0.0.1 --port 8765 | |
| response = requests.post( | |
| "http://127.0.0.1:8765/calculate-ziwei", | |
| json=test_request, | |
| timeout=10 | |
| ) | |
| if response.status_code == 200: | |
| result = response.json() | |
| print("✅ API Test Successful!\n") | |
| print(f"Status: {result['status']}") | |
| print(f"Solar Date: {result['data']['solar_date']}") | |
| print(f"Lunar Date: {result['data']['lunar_date']}") | |
| print(f"Sign: {result['data']['chart']['sign']}") | |
| print(f"Zodiac: {result['data']['chart']['zodiac']}") | |
| print(f"\n命宫: {result['data']['palaces'][3]['name']}") | |
| print(f"Major Stars: {', '.join(result['data']['palaces'][3]['major_stars'])}") | |
| print("\n🎯 All tests passed! ✨") | |
| else: | |
| print(f"❌ API returned status {response.status_code}") | |
| print(response.text) | |
| except requests.exceptions.ConnectionError: | |
| print("⚠️ API not running. Please start with:") | |
| print(" cd /Volumes/sparksverse/huggingface-spaces/astrology-ziwei-api") | |
| print(" uvicorn app:app --host 127.0.0.1 --port 8765") | |
| except Exception as e: | |
| print(f"❌ Test failed: {e}") | |