⭐ Professional Astrology Consultant

Core Source Code & Astrological Intelligence Implementation

Python 3.9 Streamlit Gemini AI Astrology Engine

🔍 About This Code Showcase

This curated code snippet demonstrates how the Professional Astrology Consultant calculates birth charts, analyzes planetary positions, and provides personalized astrological insights based on traditional western astrology principles.

Full deployment scripts, API integrations, and proprietary details are omitted for clarity and security. This showcase highlights the core astrological calculation and personality analysis algorithms.

🌟 Core Algorithm: Astrological Chart Calculator

The foundation of the Professional Astrology Consultant is its ability to calculate precise birth charts, determine planetary positions, and analyze astrological aspects for comprehensive personality and life guidance:

📄 astrology_calculator.py
import ephem import google.generativeai as genai import datetime from typing import Dict, List, Tuple import math class AstrologyCalculator: """ Professional astrology calculation engine that computes birth charts, planetary positions, and astrological aspects for comprehensive readings. """ def __init__(self, api_key: str): genai.configure(api_key=api_key) self.astro_ai = genai.GenerativeModel('gemini-pro') # Zodiac signs with their characteristics and ruling planets self.zodiac_signs = { 'Aries': {'element': 'Fire', 'quality': 'Cardinal', 'ruler': 'Mars', 'degree_range': (0, 30)}, 'Taurus': {'element': 'Earth', 'quality': 'Fixed', 'ruler': 'Venus', 'degree_range': (30, 60)}, 'Gemini': {'element': 'Air', 'quality': 'Mutable', 'ruler': 'Mercury', 'degree_range': (60, 90)}, 'Cancer': {'element': 'Water', 'quality': 'Cardinal', 'ruler': 'Moon', 'degree_range': (90, 120)}, 'Leo': {'element': 'Fire', 'quality': 'Fixed', 'ruler': 'Sun', 'degree_range': (120, 150)}, 'Virgo': {'element': 'Earth', 'quality': 'Mutable', 'ruler': 'Mercury', 'degree_range': (150, 180)} } # Astrological houses and their life areas self.houses = { 1: {'name': 'Self & Identity', 'keywords': ['personality', 'appearance', 'first impressions']}, 2: {'name': 'Money & Values', 'keywords': ['finances', 'possessions', 'self-worth']}, 3: {'name': 'Communication', 'keywords': ['siblings', 'short trips', 'learning']}, 4: {'name': 'Home & Family', 'keywords': ['roots', 'mother', 'real estate']}, 5: {'name': 'Creativity & Romance', 'keywords': ['children', 'art', 'pleasure']}, 7: {'name': 'Partnerships', 'keywords': ['marriage', 'business partners', 'open enemies']}, 10: {'name': 'Career & Reputation', 'keywords': ['profession', 'public image', 'father']} } # Major planetary aspects and their influences self.aspects = { 'conjunction': {'degrees': 0, 'orb': 8, 'nature': 'neutral', 'strength': 'major'}, 'opposition': {'degrees': 180, 'orb': 8, 'nature': 'challenging', 'strength': 'major'}, 'trine': {'degrees': 120, 'orb': 8, 'nature': 'harmonious', 'strength': 'major'}, 'square': {'degrees': 90, 'orb': 8, 'nature': 'challenging', 'strength': 'major'}, 'sextile': {'degrees': 60, 'orb': 6, 'nature': 'harmonious', 'strength': 'minor'} } def calculate_birth_chart(self, birth_date: datetime.datetime, birth_time: datetime.time, birth_location: Tuple[float, float]) -> Dict: """ Calculate complete birth chart with planetary positions and house cusps. Args: birth_date: Date of birth birth_time: Exact time of birth birth_location: (latitude, longitude) of birth location Returns: Dictionary containing complete astrological chart data """ # Combine date and time for astronomical calculations birth_datetime = datetime.datetime.combine(birth_date, birth_time) # Step 1: Calculate planetary positions planetary_positions = self._calculate_planetary_positions(birth_datetime) # Step 2: Calculate house cusps (requires birth location) house_cusps = self._calculate_house_cusps(birth_datetime, birth_location) # Step 3: Determine zodiac placements for each planet zodiac_placements = self._determine_zodiac_placements(planetary_positions) # Step 4: Calculate major aspects between planets aspects = self._calculate_planetary_aspects(planetary_positions) # Step 5: Determine planet-house relationships planet_house_positions = self._calculate_planet_houses( planetary_positions, house_cusps ) # Step 6: Generate astrological analysis chart_analysis = await self._generate_chart_analysis( zodiac_placements, aspects, planet_house_positions ) return { 'birth_info': { 'date_time': birth_datetime.isoformat(), 'location': birth_location }, 'planetary_positions': planetary_positions, 'zodiac_placements': zodiac_placements, 'house_cusps': house_cusps, 'planet_houses': planet_house_positions, 'aspects': aspects, 'chart_analysis': chart_analysis, 'chart_summary': self._generate_chart_summary(zodiac_placements, aspects) } def _calculate_planetary_positions(self, birth_datetime: datetime.datetime) -> Dict: """ Calculate precise astronomical positions of planets at birth time. Uses PyEphem for accurate celestial mechanics calculations. """ # Create observer at birth time observer = ephem.Observer() observer.date = birth_datetime planetary_positions = {} # Calculate positions for traditional astrological planets planets = { 'Sun': ephem.Sun(), 'Moon': ephem.Moon(), 'Mercury': ephem.Mercury(), 'Venus': ephem.Venus(), 'Mars': ephem.Mars(), 'Jupiter': ephem.Jupiter(), 'Saturn': ephem.Saturn(), 'Uranus': ephem.Uranus(), 'Neptune': ephem.Neptune(), 'Pluto': ephem.Pluto() } for planet_name, planet_obj in planets.items(): planet_obj.compute(observer) # Convert astronomical coordinates to astrological degrees ecliptic_longitude = math.degrees(planet_obj.hlong) planetary_positions[planet_name] = { 'longitude': ecliptic_longitude, 'latitude': math.degrees(planet_obj.hlat), 'distance': planet_obj.earth_distance, 'speed': self._calculate_planetary_speed(planet_obj, observer), 'retrograde': self._is_retrograde(planet_obj, observer) } return planetary_positions def _determine_zodiac_placements(self, planetary_positions: Dict) -> Dict: """ Determine which zodiac sign each planet occupies and calculate degrees. Provides detailed placement information for astrological interpretation. """ zodiac_placements = {} for planet, position_data in planetary_positions.items(): longitude = position_data['longitude'] # Normalize longitude to 0-360 degree range normalized_longitude = longitude % 360 # Determine zodiac sign (each sign is 30 degrees) sign_index = int(normalized_longitude // 30) degree_in_sign = normalized_longitude % 30 zodiac_sign_names = list(self.zodiac_signs.keys()) sign_name = zodiac_sign_names[sign_index] zodiac_placements[planet] = { 'sign': sign_name, 'degree': degree_in_sign, 'element': self.zodiac_signs[sign_name]['element'], 'quality': self.zodiac_signs[sign_name]['quality'], 'ruling_planet': self.zodiac_signs[sign_name]['ruler'], 'retrograde': position_data['retrograde'], 'placement_strength': self._calculate_placement_strength(planet, sign_name) } return zodiac_placements def _calculate_planetary_aspects(self, planetary_positions: Dict) -> List[Dict]: """ Calculate major and minor aspects between planets in the birth chart. Identifies harmonious and challenging planetary relationships. """ aspects = [] planet_names = list(planetary_positions.keys()) # Check every planet pair for aspects for i in range(len(planet_names)): for j in range(i + 1, len(planet_names)): planet1 = planet_names[i] planet2 = planet_names[j] lon1 = planetary_positions[planet1]['longitude'] % 360 lon2 = planetary_positions[planet2]['longitude'] % 360 # Calculate angular separation separation = abs(lon1 - lon2) if separation > 180: separation = 360 - separation # Check for major aspects within orb for aspect_name, aspect_data in self.aspects.items(): target_angle = aspect_data['degrees'] orb = aspect_data['orb'] if abs(separation - target_angle) <= orb: aspects.append({ 'planet1': planet1, 'planet2': planet2, 'aspect': aspect_name, 'exact_angle': separation, 'orb_difference': abs(separation - target_angle), 'nature': aspect_data['nature'], 'strength': aspect_data['strength'], 'interpretation': self._interpret_aspect(planet1, planet2, aspect_name) }) # Sort aspects by strength and exactness return sorted(aspects, key=lambda x: (x['strength'] == 'major', -x['orb_difference']), reverse=True)

🔮 Advanced Interpretation Engine

The interpretation engine synthesizes chart elements to provide comprehensive personality analysis, relationship compatibility, and life guidance based on traditional astrological principles:

📄 astrology_interpreter.py
class AstrologyInterpreter: async _generate_chart_analysis( self, zodiac_placements: Dict, aspects: List[Dict], planet_houses: Dict ) -> Dict: """ Generate comprehensive astrological analysis combining all chart elements. Provides insights into personality, relationships, career, and life purpose. """ analysis_prompt = f""" Provide a professional astrological reading based on this birth chart: PLANETARY PLACEMENTS: {self._format_placements_for_analysis(zodiac_placements)} MAJOR ASPECTS: {self._format_aspects_for_analysis(aspects[:5])} # Top 5 strongest aspects HOUSE POSITIONS: {self._format_houses_for_analysis(planet_houses)} Generate a comprehensive reading covering: 1. CORE PERSONALITY: Sun, Moon, and Rising sign synthesis 2. EMOTIONAL NATURE: Moon sign and aspects to emotional planets 3. COMMUNICATION STYLE: Mercury placement and aspects 4. LOVE & RELATIONSHIPS: Venus placement and 7th house analysis 5. CAREER & AMBITION: Mars, Saturn, and 10th house influences 6. LIFE CHALLENGES: Difficult aspects and their growth opportunities 7. NATURAL TALENTS: Harmonious aspects and strong planetary placements 8. SPIRITUAL PATH: Higher octave planets and their influences Provide specific, actionable insights based on traditional astrological wisdom. Include both strengths and areas for personal development. """ response = await self.astro_ai.generate_content_async(analysis_prompt) return { 'comprehensive_reading': response.text, 'personality_summary': self._extract_personality_highlights(zodiac_placements), 'elemental_balance': self._analyze_elemental_balance(zodiac_placements), 'modal_emphasis': self._analyze_modal_qualities(zodiac_placements), 'chart_patterns': self._identify_chart_patterns(aspects, planet_houses) } def _analyze_elemental_balance(self, zodiac_placements: Dict) -> Dict: """ Analyze the distribution of elements (Fire, Earth, Air, Water) in the chart. Reveals fundamental temperament and approach to life. """ element_counts = {'Fire': 0, 'Earth': 0, 'Air': 0, 'Water': 0} # Weight planets by importance (Sun, Moon, Rising get more weight) planet_weights = { 'Sun': 3, 'Moon': 3, 'Mercury': 2, 'Venus': 2, 'Mars': 2, 'Jupiter': 1, 'Saturn': 1, 'Uranus': 0.5, 'Neptune': 0.5, 'Pluto': 0.5 } for planet, placement in zodiac_placements.items(): element = placement['element'] weight = planet_weights.get(planet, 1) element_counts[element] += weight # Determine dominant and lacking elements total_weight = sum(element_counts.values()) element_percentages = {elem: (count / total_weight) * 100 for elem, count in element_counts.items()} dominant_element = max(element_percentages, key=element_percentages.get) lacking_elements = [elem for elem, pct in element_percentages.items() if pct < 15] return { 'element_distribution': element_percentages, 'dominant_element': dominant_element, 'lacking_elements': lacking_elements, 'temperament_description': self._describe_elemental_temperament(dominant_element, lacking_elements), 'balance_recommendations': self._suggest_elemental_balance(lacking_elements) } def calculate_compatibility(self, chart1: Dict, chart2: Dict) -> Dict: """ Calculate relationship compatibility between two birth charts. Analyzes synastry aspects and composite chart elements. """ # Extract key placements from both charts person1_placements = chart1['zodiac_placements'] person2_placements = chart2['zodiac_placements'] # Calculate inter-chart aspects (synastry) synastry_aspects = self._calculate_synastry_aspects( chart1['planetary_positions'], chart2['planetary_positions'] ) # Analyze elemental and modal compatibility elemental_compatibility = self._analyze_elemental_compatibility( person1_placements, person2_placements ) # Check for significant romantic indicators romantic_indicators = self._identify_romantic_indicators(synastry_aspects) # Calculate overall compatibility score compatibility_score = self._calculate_compatibility_score( synastry_aspects, elemental_compatibility, romantic_indicators ) return { 'overall_score': compatibility_score, 'synastry_aspects': synastry_aspects[:10], # Top 10 most significant 'elemental_harmony': elemental_compatibility, 'romantic_indicators': romantic_indicators, 'relationship_strengths': self._identify_relationship_strengths(synastry_aspects), 'potential_challenges': self._identify_relationship_challenges(synastry_aspects), 'compatibility_summary': await self._generate_compatibility_summary( compatibility_score, synastry_aspects, elemental_compatibility ) } def _identify_chart_patterns(self, aspects: List[Dict], planet_houses: Dict) -> List[Dict]: """ Identify significant astrological patterns in the birth chart. Recognizes Grand Trines, T-Squares, Stelliums, and other configurations. """ patterns = [] # Check for stelliums (3+ planets in same sign or house) stelliums = self._find_stelliums(planet_houses) patterns.extend(stelliums) # Check for Grand Trines (three planets forming equilateral triangle) grand_trines = self._find_grand_trines(aspects) patterns.extend(grand_trines) # Check for T-Squares (challenging configuration) t_squares = self._find_t_squares(aspects) patterns.extend(t_squares) # Check for Grand Cross (very challenging but powerful configuration) grand_crosses = self._find_grand_crosses(aspects) patterns.extend(grand_crosses) return sorted(patterns, key=lambda x: x['significance'], reverse=True)

⚙️ Technical Implementation Notes

Key Algorithms & Innovations

Why This Approach Works