Spaces:
Sleeping
Sleeping
Update astro_core.py
Browse files- astro_core.py +22 -1
astro_core.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from datetime import datetime
|
| 2 |
from typing import Dict, Any
|
|
|
|
| 3 |
import flatlib
|
| 4 |
from flatlib.datetime import Datetime
|
| 5 |
from flatlib.geopos import GeoPos
|
|
@@ -12,6 +13,23 @@ class ChartCalculator:
|
|
| 12 |
self.planets = ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars',
|
| 13 |
'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def calculate_birth_chart(self,
|
| 16 |
birth_datetime: datetime,
|
| 17 |
latitude: float,
|
|
@@ -25,8 +43,11 @@ class ChartCalculator:
|
|
| 25 |
date_str = birth_datetime.strftime("%Y/%m/%d")
|
| 26 |
time_str = birth_datetime.strftime("%H:%M")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
| 28 |
# Create flatlib datetime object
|
| 29 |
-
date = Datetime(date_str, time_str,
|
| 30 |
pos = GeoPos(latitude, longitude)
|
| 31 |
|
| 32 |
# Calculate chart
|
|
|
|
| 1 |
from datetime import datetime
|
| 2 |
from typing import Dict, Any
|
| 3 |
+
import pytz
|
| 4 |
import flatlib
|
| 5 |
from flatlib.datetime import Datetime
|
| 6 |
from flatlib.geopos import GeoPos
|
|
|
|
| 13 |
self.planets = ['Sun', 'Moon', 'Mercury', 'Venus', 'Mars',
|
| 14 |
'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']
|
| 15 |
|
| 16 |
+
def _get_utc_offset(self, dt: datetime, timezone: str) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Get UTC offset for a given datetime and timezone
|
| 19 |
+
Returns offset in format '+HH:MM' or '-HH:MM'
|
| 20 |
+
"""
|
| 21 |
+
tz = pytz.timezone(timezone)
|
| 22 |
+
offset = tz.utcoffset(dt)
|
| 23 |
+
|
| 24 |
+
# Convert timedelta to hours and minutes
|
| 25 |
+
total_seconds = int(offset.total_seconds())
|
| 26 |
+
hours = total_seconds // 3600
|
| 27 |
+
minutes = (abs(total_seconds) % 3600) // 60
|
| 28 |
+
|
| 29 |
+
# Format as string
|
| 30 |
+
sign = '+' if hours >= 0 else '-'
|
| 31 |
+
return f"{sign}{abs(hours):02d}:{minutes:02d}"
|
| 32 |
+
|
| 33 |
def calculate_birth_chart(self,
|
| 34 |
birth_datetime: datetime,
|
| 35 |
latitude: float,
|
|
|
|
| 43 |
date_str = birth_datetime.strftime("%Y/%m/%d")
|
| 44 |
time_str = birth_datetime.strftime("%H:%M")
|
| 45 |
|
| 46 |
+
# Get UTC offset for the timezone
|
| 47 |
+
utc_offset = self._get_utc_offset(birth_datetime, timezone)
|
| 48 |
+
|
| 49 |
# Create flatlib datetime object
|
| 50 |
+
date = Datetime(date_str, time_str, utc_offset)
|
| 51 |
pos = GeoPos(latitude, longitude)
|
| 52 |
|
| 53 |
# Calculate chart
|