-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart_data.py
More file actions
193 lines (157 loc) · 5.9 KB
/
chart_data.py
File metadata and controls
193 lines (157 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
"""
Core chart data extraction functions
"""
from datetime import datetime
from flatlib.chart import Chart
from flatlib.datetime import Datetime
from flatlib.geopos import GeoPos
from flatlib import const
from config import PLANET_NAMES, PLANET_CONSTANTS, logger
def create_charts(birth_date, birth_time, timezone_offset, latitude, longitude):
"""
Create natal and current charts
Args:
birth_date (str): Birth date in YYYY/MM/DD format
birth_time (str): Birth time in HH:MM format
timezone_offset (str): Timezone offset (e.g., '+00:00')
latitude (float): Latitude
longitude (float): Longitude
Returns:
tuple: (natal_chart, today_chart)
"""
now = datetime.now()
current_date = now.strftime('%Y/%m/%d')
current_time = now.strftime('%H:%M')
# Setup charts
dt = Datetime(birth_date, birth_time, timezone_offset)
pos = GeoPos(latitude, longitude)
chart = Chart(dt, pos, IDs=const.LIST_OBJECTS)
today_chart = Chart(Datetime(current_date, current_time, timezone_offset), pos, IDs=const.LIST_OBJECTS)
return chart, today_chart
def get_main_positions(chart):
"""
Get sun, moon, and ascendant from chart
Args:
chart: flatlib Chart object
Returns:
tuple: (sun, moon, ascendant) objects
"""
return chart.get('Sun'), chart.get('Moon'), chart.get('House1')
def get_planets_in_houses(chart):
"""
Get all planets organized by houses
Args:
chart: flatlib Chart object
Returns:
dict: Dictionary keyed by house number with planet data
"""
houses = chart.houses
planets_in_houses = {}
for house in houses:
house_number = int(house.id.replace('House', ''))
planets_in_houses[house_number] = {
'house_obj': house,
'planets': []
}
# Get all objects in this house
objects_in_house = chart.objects.getObjectsInHouse(house)
for obj in objects_in_house:
if obj.id in PLANET_NAMES:
planets_in_houses[house_number]['planets'].append({
'name': obj.id,
'sign': obj.sign,
'object': obj
})
return planets_in_houses
def get_current_planets(today_chart):
"""
Get current planet positions and retrograde status
Args:
today_chart: flatlib Chart object for current date/time
Returns:
dict: Dictionary with planet positions and retrograde status
"""
current_planets = {}
for planet_name, planet_const in PLANET_CONSTANTS.items():
try:
planet_obj = today_chart.get(planet_const)
# Check if planet object exists and has the required attributes
if planet_obj and hasattr(planet_obj, 'sign') and hasattr(planet_obj, 'signlon'):
retrograde = False
# Sun and Moon don't go retrograde
if planet_name not in ['Sun', 'Moon']:
if hasattr(planet_obj, 'isRetrograde'):
try:
retrograde = planet_obj.isRetrograde()
except Exception:
retrograde = False
current_planets[planet_name] = {
'sign': planet_obj.sign,
'degree': float(planet_obj.signlon),
'retrograde': retrograde
}
except Exception as e:
# Skip planets that cause errors but continue with others
logger.warning(f"Could not get data for {planet_name}: {e}")
continue
return current_planets
def get_full_chart_structure(birth_date, birth_time, timezone_offset, latitude, longitude):
"""
Get complete natal chart structure with all planets and houses
Args:
birth_date (str): Birth date in YYYY/MM/DD format
birth_time (str): Birth time in HH:MM format
timezone_offset (str): Timezone offset (e.g., '+00:00')
latitude (float): Latitude
longitude (float): Longitude
Returns:
dict: Complete chart structure with sun, moon, ascendant, planets, and houses
"""
# Create chart
dt = Datetime(birth_date, birth_time, timezone_offset)
pos = GeoPos(latitude, longitude)
chart_obj = Chart(dt, pos, IDs=const.LIST_OBJECTS)
# Get main positions
sun = chart_obj.get('Sun')
moon = chart_obj.get('Moon')
ascendant = chart_obj.get('House1')
# Get all planets with detailed information
planets = {}
for planet_name, planet_const in PLANET_CONSTANTS.items():
try:
planet_obj = chart_obj.get(planet_const)
if planet_obj and hasattr(planet_obj, 'sign') and hasattr(planet_obj, 'signlon'):
planets[planet_name] = {
'sign': planet_obj.sign,
'degree': float(planet_obj.signlon),
'house': None
}
except Exception as e:
logger.warning(f"Could not get data for {planet_name}: {e}")
continue
# Get all houses
houses = chart_obj.houses
house_data = {}
for house in houses:
house_number = int(house.id.replace('House', ''))
house_data[house_number] = {
'sign': house.sign,
'degree': float(house.signlon),
'planets': []
}
objects_in_house = chart_obj.objects.getObjectsInHouse(house)
for obj in objects_in_house:
if obj.id in planets:
planets[obj.id]['house'] = house_number
house_data[house_number]['planets'].append({
'name': obj.id,
'sign': obj.sign,
'degree': float(obj.signlon)
})
return {
'sun': sun.sign,
'moon': moon.sign,
'ascendant': ascendant.sign,
'planets': planets,
'houses': house_data
}