v good
Browse files
app.py
CHANGED
@@ -9,6 +9,227 @@ from datetime import datetime
|
|
9 |
localrun = False # 上傳到 Space 時要設定成 False
|
10 |
DESKTOP_KEY = False
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def get_envkey():
|
13 |
from dotenv import load_dotenv, find_dotenv
|
14 |
_ = load_dotenv(find_dotenv()) # read local .env file
|
@@ -99,7 +320,17 @@ def GWAI(year, month, day, btime, sex) -> datetime:
|
|
99 |
z = int((hour + 1) / 2) + 1
|
100 |
result=z_mapping[str(z)]
|
101 |
output=(bstr.replace('农历','農曆') + " " + result + "時")
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
return output,output2
|
104 |
|
105 |
|
|
|
9 |
localrun = False # 上傳到 Space 時要設定成 False
|
10 |
DESKTOP_KEY = False
|
11 |
|
12 |
+
# 排紫微盤的參考變數
|
13 |
+
solar_year = 1998
|
14 |
+
solar_month = 5
|
15 |
+
solar_day = 18
|
16 |
+
time_hour = 3
|
17 |
+
time_min = 14
|
18 |
+
gender = 0
|
19 |
+
|
20 |
+
|
21 |
+
zi_adjust = 2
|
22 |
+
|
23 |
+
'''
|
24 |
+
排盤有以下幾個步驟
|
25 |
+
|
26 |
+
1. 安十二宮
|
27 |
+
|
28 |
+
2. 起寅首、定納音五行局
|
29 |
+
|
30 |
+
3. 定紫微星
|
31 |
+
|
32 |
+
4. 安主星
|
33 |
+
|
34 |
+
5. 安四化星
|
35 |
+
|
36 |
+
'''
|
37 |
+
|
38 |
+
def gen_chart(solar_year, solar_month, solar_day, time_hour, time_min, gender):
|
39 |
+
from datetime import timedelta, datetime
|
40 |
+
|
41 |
+
# 六十甲子納音歌
|
42 |
+
fiveoldsong = [ 4, 2, 6, 4, 2, 6, 2, 6, 5, 2, 6, 5, 6, 5, 3, 6, 5, 3, 5, 3, 4, 5, 3, 4, 3, 4, 2, 3, 4, 2 ];
|
43 |
+
|
44 |
+
# 五行局
|
45 |
+
fiveway = ['水二局','木三局','金四局','土五局','火六局']
|
46 |
+
|
47 |
+
# 紫微星查表
|
48 |
+
ziwei_table = [2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,1,1,2,2,3,3,4,4,5,5,2,3,6,3,4,7,4,5,8,5,6,9,6,7,10,7,8,11,8,9,12,9,10,1,10,11,2,11,12,12,5,2,3,1,6,3,4,2,7,4,5,3,8,5,6,4,9,6,7,5,10,7,8,6,11,8,9,7,12,7,12,5,2,3,8,1,6,3,4,9,2,7,4,5,10,3,8,5,6,11,5,9,6,7,12,5,10,7,8,10,7,12,5,2,3,11,8,1,6,3,4,12,9,2,7,4,5,1,10,3,8,5,6,2,11,4,9,6,7];
|
49 |
+
|
50 |
+
# 天府星查表
|
51 |
+
tianfu_table = [5,4,3,2,1,12,11,10,9,8,7,6]
|
52 |
+
|
53 |
+
def get_year_hepos(birthdatetime):
|
54 |
+
start_year = (birthdatetime.year - 3) % 60
|
55 |
+
hs_pos = start_year % 10
|
56 |
+
if hs_pos == 0:
|
57 |
+
hs_pos = 10
|
58 |
+
gb_pos = start_year % 12
|
59 |
+
if gb_pos == 0:
|
60 |
+
gb_pos = 12
|
61 |
+
year_hepos = [hs_pos, gb_pos]
|
62 |
+
return year_hepos
|
63 |
+
|
64 |
+
def get_birth_time_epos(birthdatetime):
|
65 |
+
if birthdatetime.hour in range(23, 1):
|
66 |
+
return 1
|
67 |
+
elif birthdatetime.hour in range(1, 3):
|
68 |
+
return 2
|
69 |
+
elif birthdatetime.hour in range(3, 5):
|
70 |
+
return 3
|
71 |
+
elif birthdatetime.hour in range(5, 7):
|
72 |
+
return 4
|
73 |
+
elif birthdatetime.hour in range(7, 9):
|
74 |
+
return 5
|
75 |
+
elif birthdatetime.hour in range(9, 11):
|
76 |
+
return 6
|
77 |
+
elif birthdatetime.hour in range(11, 13):
|
78 |
+
return 7
|
79 |
+
elif birthdatetime.hour in range(13, 15):
|
80 |
+
return 8
|
81 |
+
elif birthdatetime.hour in range(15, 17):
|
82 |
+
return 9
|
83 |
+
elif birthdatetime.hour in range(17, 19):
|
84 |
+
return 10
|
85 |
+
elif birthdatetime.hour in range(19, 21):
|
86 |
+
return 11
|
87 |
+
elif birthdatetime.hour in range(21, 23):
|
88 |
+
return 12
|
89 |
+
return 1
|
90 |
+
|
91 |
+
def get_self_palace_epos(birthdatetime, isleap):
|
92 |
+
|
93 |
+
month_position = birthdatetime.month
|
94 |
+
hour_position = get_birth_time_epos(birthdatetime)
|
95 |
+
|
96 |
+
#檢查是否為閏月
|
97 |
+
if isleap == True:
|
98 |
+
if Zwsetting.intercalary_month == 2:
|
99 |
+
month_position += 1
|
100 |
+
elif Zwsetting.intercalary_month == 3:
|
101 |
+
if birthdatetime.day > 15:
|
102 |
+
month_position += 1
|
103 |
+
# 直接將月份 +3 的原因是: +2 是為了將寅起調整成子起,另外的 +1 是因為計算時間時本格也算一次,所以 +1 調整回來。
|
104 |
+
position = ( month_position + 3 - hour_position )%12
|
105 |
+
position = 12 if position == 0 else position
|
106 |
+
|
107 |
+
return position
|
108 |
+
|
109 |
+
def get_body_palace_epos(birthdatetime, isleap):
|
110 |
+
|
111 |
+
month_position = birthdatetime.month
|
112 |
+
hour_position = get_birth_time_epos(birthdatetime)
|
113 |
+
|
114 |
+
#檢查是否為閏月(先不用管閏十二月,最接近的兩年 1889年,2500年)
|
115 |
+
if isleap == True:
|
116 |
+
if Zwsetting.intercalary_month == 2:
|
117 |
+
month_position += 1
|
118 |
+
elif Zwsetting.intercalary_month == 3:
|
119 |
+
if birthdatetime.day > 15:
|
120 |
+
month_position += 1
|
121 |
+
|
122 |
+
# 直接將月份 +1 的原因是: +2 是為了將寅起調整成子起,另外的 -1 是因為計算時間時本格也算一次,所以 -1 調整回來。
|
123 |
+
position = ( month_position + 1 + hour_position )%12
|
124 |
+
position = 12 if position == 0 else position
|
125 |
+
return position
|
126 |
+
|
127 |
+
def get_yin_hpos(birthdatetime):
|
128 |
+
start_year = (birthdatetime.year - 3) % 60
|
129 |
+
hs_pos = start_year % 10
|
130 |
+
if hs_pos == 0:
|
131 |
+
hs_pos = 10
|
132 |
+
self_hpos = ((1+hs_pos*2) % 10)
|
133 |
+
return self_hpos
|
134 |
+
|
135 |
+
#chart_data = solar_year +'/'+ solar_month +'/'+ solar_day +'/'+ str(time_hour)+':'+str(time_min)+'/'+str(gender)
|
136 |
+
#print(str(chart_data))
|
137 |
+
|
138 |
+
solar_birth_datetime = datetime(int(solar_year), int(solar_month), int(solar_day), time_hour, time_min)
|
139 |
+
|
140 |
+
#夜子時設定檢查
|
141 |
+
if zi_adjust == 2 and time_hour >= 23 :
|
142 |
+
solar_birth_datetime = solar_birth_datetime + timedelta(days=1)
|
143 |
+
|
144 |
+
# 跳過 農曆轉換
|
145 |
+
#lunar = Zwbase.get_lunar_datetime(solar_birth_datetime)
|
146 |
+
#lunar_birth_datetime = LunarDatetime(lunar.lunarYear, lunar.lunarMonth, lunar.lunarDay, solar_birth_datetime.hour, solar_birth_datetime.minute, lunar.isleap)
|
147 |
+
|
148 |
+
# 取得生辰年干支位置
|
149 |
+
year_hepos = get_year_hepos(solar_birth_datetime)
|
150 |
+
|
151 |
+
# 取得陰陽性別位置
|
152 |
+
# 性別
|
153 |
+
if gender == 2:
|
154 |
+
gender_pos = 2
|
155 |
+
else:
|
156 |
+
gender_pos = 3
|
157 |
+
|
158 |
+
# 陰陽
|
159 |
+
yin_yang_pos = 0 if year_hepos[0] % 2 == 1 else 1
|
160 |
+
|
161 |
+
|
162 |
+
# 取得生辰地支位置
|
163 |
+
birth_time_epos = get_birth_time_epos(solar_birth_datetime)
|
164 |
+
|
165 |
+
# 取得命宮地支位置
|
166 |
+
self_palace_epos = get_self_palace_epos(solar_birth_datetime, False) ## 閏年處理 lunar.isleap
|
167 |
+
|
168 |
+
# 取得寅宮天干位置
|
169 |
+
yin_hpos = get_yin_hpos(solar_birth_datetime)
|
170 |
+
|
171 |
+
# 取得命宮天干位置
|
172 |
+
# - 計算命宮-寅宮順向距離
|
173 |
+
self_yin_dist = 0
|
174 |
+
if self_palace_epos >= 3:
|
175 |
+
self_yin_dist = self_palace_epos - 3
|
176 |
+
else:
|
177 |
+
self_yin_dist = self_palace_epos + 9
|
178 |
+
# - 計算命宮天干位置
|
179 |
+
self_palace_hpos = 0
|
180 |
+
if (self_yin_dist + yin_hpos) > 10:
|
181 |
+
self_palace_hpos = (self_yin_dist + yin_hpos) - 10
|
182 |
+
else:
|
183 |
+
self_palace_hpos = self_yin_dist + yin_hpos
|
184 |
+
|
185 |
+
|
186 |
+
# 取得身宮位置
|
187 |
+
body_palace_epos = get_body_palace_epos(solar_birth_datetime, False)
|
188 |
+
|
189 |
+
# 取得五行局
|
190 |
+
fiveway_param_1 = int(( self_palace_hpos + 1) / 2 if self_palace_hpos % 2 == 1 else self_palace_hpos / 2 )
|
191 |
+
fiveway_param_2 = int(( self_palace_epos + 1) / 2 if self_palace_epos % 2 == 1 else self_palace_epos / 2 )
|
192 |
+
fiveway_pos = fiveoldsong[(fiveway_param_1 - 1) * 6 + fiveway_param_2 - 1]
|
193 |
+
|
194 |
+
# 取得紫微星位置
|
195 |
+
ziwei_pos = ziwei_table[(fiveway_pos -2) * 30 + int(solar_day)-1] ## lunar.lunarDay - 1
|
196 |
+
|
197 |
+
# 取得天府星位置
|
198 |
+
tianfu_pos = tianfu_table[ziwei_pos-1]
|
199 |
+
outstr=f'紫微在= {ziwei_pos} 五行局= {fiveway_pos} 命宮= {self_palace_epos}'
|
200 |
+
|
201 |
+
return outstr
|
202 |
+
|
203 |
+
'''
|
204 |
+
# 產生 chat(命盤) 物件
|
205 |
+
chart = Chart( [self_palace_hpos, self_palace_epos], body_palace_epos)
|
206 |
+
chart.birth_year_hepos = year_hepos
|
207 |
+
chart.birth_time_epos = birth_time_epos
|
208 |
+
chart.yin_hpos = yin_hpos
|
209 |
+
chart.yin_yang_gender = [ yin_yang_pos, gender_pos]
|
210 |
+
chart.ziwei_pos = ziwei_pos
|
211 |
+
chart.fiveway_pos = fiveway_pos
|
212 |
+
chart.lifechart_type = (chart.ziwei_pos -1)*12 + chart.self_palace_hepos[1]
|
213 |
+
|
214 |
+
# 產生十二宮 (一共會產生 13宮,第 0 宮不使用)
|
215 |
+
for i in range(0, 13, 1):
|
216 |
+
chart.palaces.append(Palace(i))
|
217 |
+
|
218 |
+
# 排(產生)十二個主星
|
219 |
+
chart = gen_star(chart, ziwei_pos, tianfu_pos, year_hepos, birth_time_epos, solar_birth_datetime, Fasle) # lunar.isleap
|
220 |
+
|
221 |
+
# 檢查星耀 (第 0 宮不使用)
|
222 |
+
for p_index, palace in enumerate(chart.palaces):
|
223 |
+
if p_index > 0:
|
224 |
+
|
225 |
+
age_string = '['+str(palace.age[0])+'~'+str(palace.age[1])+']'
|
226 |
+
name_string = '['+str(palace.name)+'-'+str(palace.pos[1])+']'
|
227 |
+
|
228 |
+
for index, star in enumerate(palace.stars):
|
229 |
+
star_weight_string = '('+str(Zwsetting.star_weight[star.weight])+')'
|
230 |
+
return True
|
231 |
+
'''
|
232 |
+
|
233 |
def get_envkey():
|
234 |
from dotenv import load_dotenv, find_dotenv
|
235 |
_ = load_dotenv(find_dotenv()) # read local .env file
|
|
|
320 |
z = int((hour + 1) / 2) + 1
|
321 |
result=z_mapping[str(z)]
|
322 |
output=(bstr.replace('农历','農曆') + " " + result + "時")
|
323 |
+
|
324 |
+
import re
|
325 |
+
match = re.search(r'(\d+)年(\d+)月(\d+)日', output)
|
326 |
+
|
327 |
+
if match:
|
328 |
+
my_year = match.group(1)
|
329 |
+
my_month = match.group(2)
|
330 |
+
my_day = match.group(3)
|
331 |
+
|
332 |
+
print('<<',my_year,my_month,my_day,'>>')
|
333 |
+
output2=gen_chart(int(my_year), int(my_month), int(my_day), hour, int(10), int(2))
|
334 |
return output,output2
|
335 |
|
336 |
|