hermes-astrology / test_astroseek.py
aamanlamba's picture
Add test_astroseek.py - Astroseek integration support
c86b625 verified
raw
history blame
10.9 kB
#!/usr/bin/env python3
"""
Test Astroseek MCP Integration
Run this to test the Astroseek.com chart data integration
"""
import sys
from datetime import datetime
def test_astroseek_basic():
"""Test basic Astroseek MCP functionality"""
print("\n" + "="*80)
print("🌟 ASTROSEEK MCP INTEGRATION TEST")
print("="*80)
try:
from astroseek_mcp import AstroseekMCP, get_mcp_tools
print("\nβœ… Successfully imported AstroseekMCP")
# Initialize client
client = AstroseekMCP()
print("βœ… AstroseekMCP client initialized")
# Test 1: Get available tools
print("\n" + "-"*80)
print("TEST 1: Available MCP Tools")
print("-"*80)
tools = get_mcp_tools()
print(f"\nπŸ“‹ Found {len(tools)} Astroseek MCP tools:")
for i, tool in enumerate(tools, 1):
print(f"\n{i}. {tool['name']}")
print(f" Description: {tool['description']}")
print(f" Parameters: {tool['parameters']}")
# Test 2: Chart calculation (simulated)
print("\n" + "-"*80)
print("TEST 2: Chart Calculation (Example)")
print("-"*80)
print("\n⚠️ Note: This is a web scraping integration.")
print(" Actual chart calculation requires:")
print(" - Internet connection")
print(" - Astroseek.com to be accessible")
print(" - Proper HTML structure (may change)")
# Example parameters
example_birth_date = "1990-01-15"
example_birth_time = "12:00"
example_lat = 40.7128
example_lon = -74.0060
print(f"\nπŸ“… Example Chart Data:")
print(f" Birth Date: {example_birth_date}")
print(f" Birth Time: {example_birth_time}")
print(f" Location: {example_lat}, {example_lon}")
print(f" (New York City)")
print("\nπŸ’‘ To run actual chart calculation:")
print(" result = client.calculate_chart(")
print(f" birth_date='{example_birth_date}',")
print(f" birth_time='{example_birth_time}',")
print(f" latitude={example_lat},")
print(f" longitude={example_lon}")
print(" )")
# Test 3: Daily horoscope (example)
print("\n" + "-"*80)
print("TEST 3: Daily Horoscope (Example)")
print("-"*80)
print("\nπŸ“– Example: Get Aries daily horoscope")
print(" result = client.get_daily_horoscope('Aries')")
print("\n Returns:")
print(" {")
print(" 'sign': 'Aries',")
print(" 'date': 'today',")
print(" 'horoscope': '...',")
print(" 'source': 'astroseek.com'")
print(" }")
# Test 4: Transits (example)
print("\n" + "-"*80)
print("TEST 4: Current Transits (Example)")
print("-"*80)
print("\n🌍 Example: Get current planetary transits")
print(" result = client.get_transits()")
print("\n Returns:")
print(" {")
print(" 'date': 'current',")
print(" 'planets': { ... },")
print(" 'source': 'astroseek.com'")
print(" }")
print("\n" + "="*80)
print("βœ… ASTROSEEK MCP TESTS COMPLETED")
print("="*80)
return True
except ImportError as e:
print(f"\n❌ Import Error: {e}")
print("\nπŸ’‘ Make sure astroseek_mcp.py is in the same directory")
return False
except Exception as e:
print(f"\n❌ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_live_horoscope():
"""Test live daily horoscope fetch (requires internet)"""
print("\n" + "="*80)
print("πŸ”΄ LIVE TEST: Daily Horoscope")
print("="*80)
print("\n⚠️ This test requires internet connection")
print("⚠️ This will make a real request to astroseek.com")
response = input("\nDo you want to run live test? (yes/no): ")
if response.lower() != 'yes':
print("⏭️ Skipping live test")
return True
try:
from astroseek_mcp import AstroseekMCP
client = AstroseekMCP()
# Test with Aries
print("\nπŸ“‘ Fetching Aries daily horoscope from astroseek.com...")
result = client.get_daily_horoscope("Aries")
if "error" in result:
print(f"\n⚠️ Error: {result['error']}")
print("\nNote: This is expected if:")
print(" - No internet connection")
print(" - Astroseek changed their HTML structure")
print(" - Rate limiting or blocking")
else:
print("\nβœ… Successfully fetched horoscope!")
print(f"\nSign: {result.get('sign', 'N/A')}")
print(f"Date: {result.get('date', 'N/A')}")
print(f"Horoscope: {result.get('horoscope', 'N/A')[:200]}...")
print(f"Source: {result.get('source', 'N/A')}")
return True
except Exception as e:
print(f"\n❌ Live test failed: {e}")
print("\nThis is normal - web scraping requires:")
print(" - Specific HTML structure")
print(" - Rate limiting compliance")
print(" - Consider using official APIs instead")
return False
def show_usage_guide():
"""Show how to use Astroseek MCP in your code"""
print("\n" + "="*80)
print("πŸ“š ASTROSEEK MCP USAGE GUIDE")
print("="*80)
guide = """
1️⃣ BASIC USAGE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
from astroseek_mcp import AstroseekMCP
# Initialize client
client = AstroseekMCP()
# Calculate natal chart
chart = client.calculate_chart(
birth_date="1990-01-15",
birth_time="12:00",
latitude=40.7128,
longitude=-74.0060,
timezone="America/New_York"
)
# Access chart data
planets = chart.get('planets', {})
houses = chart.get('houses', [])
aspects = chart.get('aspects', [])
2️⃣ DAILY HOROSCOPE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Get daily horoscope for any sign
horoscope = client.get_daily_horoscope("Leo")
print(horoscope['sign']) # "Leo"
print(horoscope['date']) # "today"
print(horoscope['horoscope']) # Horoscope text
3️⃣ CURRENT TRANSITS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Get current planetary positions
transits = client.get_transits()
# Or get transits for specific date
transits = client.get_transits(date="2025-12-31")
4️⃣ MCP INTEGRATION
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
from mcp_client import MCPClient
# Use via MCP client
mcp = MCPClient(mode="local")
# Access Astroseek tools through MCP
tools = mcp.get_tools()
5️⃣ IMPORTANT NOTES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ Web Scraping Limitations:
- Requires internet connection
- Subject to Astroseek's HTML structure changes
- Rate limiting (1 request per second)
- May violate TOS - check before production use
βœ… Better Alternatives:
- Astro.com API (official)
- Swiss Ephemeris (pyswisseph) - local calculations
- AstroDienst API
- Astronomy API services
πŸ’‘ This integration is a PROOF-OF-CONCEPT for:
- MCP server architecture
- External API integration
- Hackathon demonstration
πŸ“ For production use, consider:
- Official APIs with proper authentication
- Local ephemeris calculations
- Caching and rate limiting
- Terms of service compliance
6️⃣ TROUBLESHOOTING
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Error: "Failed to fetch chart"
β†’ Check internet connection
β†’ Verify Astroseek.com is accessible
β†’ HTML structure may have changed
Error: "Rate limit exceeded"
β†’ Wait between requests (1 sec minimum)
β†’ Consider caching results
Error: "No data found"
β†’ Astroseek HTML structure changed
β†’ Update parsing logic in _extract_* methods
7️⃣ EXAMPLE: FULL WORKFLOW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
from astroseek_mcp import AstroseekMCP
# Initialize
client = AstroseekMCP()
# Get chart
chart = client.calculate_chart(
birth_date="1990-01-15",
birth_time="12:00",
latitude=40.7128,
longitude=-74.0060
)
# Check for errors
if "error" in chart:
print(f"Error: {chart['error']}")
else:
# Process chart data
print(f"Planets: {chart['planets']}")
print(f"Houses: {chart['houses']}")
print(f"Aspects: {chart['aspects']}")
# Get today's horoscope
horoscope = client.get_daily_horoscope("Aries")
print(horoscope.get('horoscope', 'N/A'))
# Get current transits
transits = client.get_transits()
print(transits.get('planets', {}))
"""
print(guide)
def main():
"""Main test runner"""
print("\n" + "="*80)
print("πŸ§ͺ ASTROSEEK MCP INTEGRATION TEST SUITE")
print("="*80)
print(f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# Run basic tests
success = test_astroseek_basic()
if success:
# Optionally run live tests
test_live_horoscope()
# Show usage guide
show_usage_guide()
print("\n" + "="*80)
print("βœ… TEST SUITE COMPLETE")
print("="*80)
if success:
print("\nβœ… Astroseek MCP integration is working")
print("\nπŸ“š Key Files:")
print(" - astroseek_mcp.py: Main integration code")
print(" - .mcp_config.json: MCP server configuration")
print(" - mcp_client.py: MCP client for all integrations")
print("\nπŸ’‘ Next Steps:")
print(" 1. Review astroseek_mcp.py for implementation")
print(" 2. Test live connections (optional)")
print(" 3. Consider official APIs for production")
print(" 4. Update HTML parsing if Astroseek changes")
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())