-
Notifications
You must be signed in to change notification settings - Fork 12
/
VedicAstroAPI.py
114 lines (102 loc) · 4.88 KB
/
VedicAstroAPI.py
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
from typing import Optional
from pydantic import BaseModel
from fastapi import FastAPI
from concurrent.futures import ThreadPoolExecutor
from fastapi.middleware.cors import CORSMiddleware
from vedicastro import VedicAstro, horary_chart, utils
app = FastAPI()
class ChartInput(BaseModel):
year: int
month: int
day: int
hour: int
minute: int
second: int
utc: str
latitude: float
longitude: float
ayanamsa: str = "Lahiri"
house_system: str = "Equal"
return_style: Optional[str] = None
class HoraryChartInput(BaseModel):
horary_number: int
year: int
month: int
day: int
hour: int
minute: int
second: int
utc: str
latitude: float
longitude: float
ayanamsa: str = "Krishnamurti"
house_system: str = "Placidus"
return_style: Optional[str] = None
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_credentials=True,
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)
@app.get("/")
async def read_root():
return {"message": "Welcome to VedicAstro FastAPI Service!",
"info": "Visit http://127.0.0.1:8088/docs to test the API functions"}
@app.post("/get_all_horoscope_data")
async def get_chart_data(input: ChartInput):
"""
Generates all data for a given time and location, based on the selected ayanamsa & house system
"""
horoscope = VedicAstro.VedicHoroscopeData(input.year, input.month, input.day,
input.hour, input.minute, input.second,
input.utc, input.latitude, input.longitude,
input.ayanamsa, input.house_system)
chart = horoscope.generate_chart()
planets_data = horoscope.get_planets_data_from_chart(chart)
houses_data = horoscope.get_houses_data_from_chart(chart)
planet_significators = horoscope.get_planet_wise_significators(planets_data, houses_data)
planetary_aspects = horoscope.get_planetary_aspects(chart)
house_significators = horoscope.get_house_wise_significators(planets_data, houses_data)
vimshottari_dasa_table = horoscope.compute_vimshottari_dasa(chart)
consolidated_chart_data = horoscope.get_consolidated_chart_data(planets_data=planets_data,
houses_data=houses_data,
return_style = input.return_style)
return {
"planets_data": [planet._asdict() for planet in planets_data],
"houses_data": [house._asdict() for house in houses_data],
"planet_significators": planet_significators,
"planetary_aspects": planetary_aspects,
"house_significators": house_significators,
"vimshottari_dasa_table": vimshottari_dasa_table,
"consolidated_chart_data": consolidated_chart_data
}
@app.post("/get_all_horary_data")
async def get_horary_data(input: HoraryChartInput):
"""
Generates all data for a given horary number, time and location as per KP Astrology system
"""
matched_time, vhd_hora_houses_chart, houses_data = horary_chart.find_exact_ascendant_time(input.year, input.month, input.day, input.utc, input.latitude, input.longitude, input.horary_number, input.ayanamsa)
vhd_hora = VedicAstro.VedicHoroscopeData(input.year, input.month, input.day,
input.hour, input.minute, input.second,
input.utc, input.latitude, input.longitude,
input.ayanamsa, input.house_system)
vhd_hora_planets_chart = vhd_hora.generate_chart()
planets_data = vhd_hora.get_planets_data_from_chart(vhd_hora_planets_chart, vhd_hora_houses_chart)
planet_significators = vhd_hora.get_planet_wise_significators(planets_data, houses_data)
planetary_aspects = vhd_hora.get_planetary_aspects(vhd_hora_planets_chart)
house_significators = vhd_hora.get_house_wise_significators(planets_data, houses_data)
vimshottari_dasa_table = vhd_hora.compute_vimshottari_dasa(vhd_hora_planets_chart)
consolidated_chart_data = vhd_hora.get_consolidated_chart_data(planets_data=planets_data,
houses_data=houses_data,
return_style = input.return_style)
return {
"planets_data": [planet._asdict() for planet in planets_data],
"houses_data": [house._asdict() for house in houses_data],
"planet_significators": planet_significators,
"planetary_aspects": planetary_aspects,
"house_significators": house_significators,
"vimshottari_dasa_table": vimshottari_dasa_table,
"consolidated_chart_data": consolidated_chart_data
}