-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
1065 lines (1009 loc) · 60.4 KB
/
config.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Wed May 17 11:55:49 2023
@author: kentang
"""
import re
import math
import datetime
from itertools import cycle, repeat
from sxtwl import fromSolar
import ephem
cnum = list("一二三四五六七八九十")
#干支
tian_gan = '甲乙丙丁戊己庚辛壬癸'
di_zhi = '子丑寅卯辰巳午未申酉戌亥'
cnumber = list("一二三四五六七八九")
door_r = list("休生傷杜景死驚開")
star_r = list("蓬任沖輔英禽柱心")
eight_gua = list("坎坤震巽中乾兌艮離")
clockwise_eightgua = list("坎艮震巽離坤兌乾")
golen_d = re.findall("..","太乙攝提軒轅招搖天符青龍咸池太陰天乙")
wuxing = "火水金火木金水土土木,水火火金金木土水木土,火火金金木木土土水水,火木水金木水土火金土,木火金水水木火土土金"
wuxing_relation_2 = dict(zip(list(map(
lambda x: tuple(re.findall("..",x)), wuxing.split(","))),
"尅我,我尅,比和,生我,我生".split(",")))
cmonth = list("一二三四五六七八九十") + ["十一","十二"]
jieqi_name = re.findall('..', '春分清明穀雨立夏小滿芒種夏至小暑大暑立秋處暑白露秋分寒露霜降立冬小雪大雪冬至小寒大寒立春雨水驚蟄')
jj = {"甲子":"戊","甲戌":"己","甲申":"庚","甲午":"辛","甲辰":"壬","甲寅":"癸"}
door_wuxing = dict(zip(door_r,"水土木木火土金金"))
star_wuxing = dict(zip(star_r,"水土木木火土金金"))
#%% 基本功能函數
def split_list(lst, chunk_size):
return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]
def multi_key_dict_get(d, k):
for keys, v in d.items():
if k in keys:
return v
return None
def new_list(olist, o):
a = olist.index(o)
res1 = olist[a:] + olist[:a]
return res1
def new_list_r(olist, o):
zhihead_code = olist.index(o)
res1 = []
for i in range(len(olist)):
res1.append(olist[zhihead_code % len(olist)])
zhihead_code = zhihead_code - 1
return res1
def gendatetime(year, month, day, hour):
return "{}年{}月{}日{}時".format(year, month, day, hour)
def repeat_list(n, thelist):
return [repetition for i in thelist for repetition in repeat(i,n)]
#%% 甲子平支
def jiazi():
return list(map(lambda x: "{}{}".format(tian_gan[x % len(tian_gan)],
di_zhi[x % len(di_zhi)]),
list(range(60))))
def Ganzhiwuxing(gangorzhi):
gz_list = "甲寅乙卯震巽,丙巳丁午離,壬亥癸子坎,庚申辛酉乾兌,未丑戊己未辰戌艮坤".split(",")
ganzhiwuxing = dict(zip(list(map(lambda x: tuple(x), gz_list
)), list("木火水金土")))
return multi_key_dict_get(ganzhiwuxing, gangorzhi)
def jieqicode(year,month, day, hour, minute):
"""以年月日時分節氣找奇門上中下元局"""
return multi_key_dict_get({("冬至", "驚蟄"): "一七四",
"小寒": "二八五",
("大寒", "春分"): "三九六",
"立春":"八五二",
"雨水":"九六三",
("清明", "立夏"): "四一七",
("穀雨", "小滿"): "五二八",
"芒種": "六三九",
("夏至", "白露"): "九三六",
"小暑":"八二五",
("大暑", "秋分"): "七一四",
"立秋":"二五八",
"處暑":"一四七",
("霜降", "小雪"): "五八二",
("寒露", "立冬"): "六九三",
"大雪":"四七一"},
jq(year,month, day,hour, minute))
def jieqicode_jq(jq):
"""以節氣名稱找奇門上中下元局"""
return multi_key_dict_get({("冬至", "驚蟄"): "一七四",
"小寒": "二八五",
("大寒", "春分"): "三九六",
"立春":"八五二",
"雨水":"九六三",
("清明", "立夏"): "四一七",
("穀雨", "小滿"): "五二八",
"芒種": "六三九",
("夏至", "白露"): "九三六",
"小暑":"八二五",
("大暑", "秋分"): "七一四",
"立秋":"二五八",
"處暑":"一四七",
("霜降", "小雪"): "五八二",
("寒露", "立冬"): "六九三",
"大雪":"四七一"},
jq)
def findyuen(year, month, day, hour, minute):
gz = gangzhi(year, month, day, hour, minute)
return multi_key_dict_get(findyuen_dict(), gz[2])
def findyuen_minute(year, month, day, hour, minute):
gz = gangzhi(year, month, day, hour, minute)
return multi_key_dict_get(findyuen_dict(), gz[3])
def find_wx_relation(zhi1, zhi2):
combine_zhi = Ganzhiwuxing(zhi1) + Ganzhiwuxing(zhi2)
return multi_key_dict_get(wuxing_relation_2, combine_zhi)
#換算干支
def gangzhi1(year, month, day, hour, minute):
if hour == 23:
d = ephem.Date(round((ephem.Date("{}/{}/{} {}:00:00.00".format(
str(year).zfill(4),
str(month).zfill(2),
str(day+1).zfill(2),
str(0).zfill(2)))),3))
else:
d = ephem.Date("{}/{}/{} {}:00:00.00".format(
str(year).zfill(4),
str(month).zfill(2),
str(day).zfill(2),
str(hour).zfill(2)))
dd = list(d.tuple())
cdate = fromSolar(dd[0], dd[1], dd[2])
yTG,mTG,dTG,hTG = "{}{}".format(
tian_gan[cdate.getYearGZ().tg],
di_zhi[cdate.getYearGZ().dz]), "{}{}".format(
tian_gan[cdate.getMonthGZ().tg],
di_zhi[cdate.getMonthGZ().dz]), "{}{}".format(
tian_gan[cdate.getDayGZ().tg],
di_zhi[cdate.getDayGZ().dz]), "{}{}".format(
tian_gan[cdate.getHourGZ(dd[3]).tg],
di_zhi[cdate.getHourGZ(dd[3]).dz])
if year < 1900:
mTG1 = find_lunar_month(yTG).get(lunar_date_d(year, month, day).get("月"))
else:
mTG1 = mTG
hTG1 = find_lunar_hour(dTG).get(hTG[1])
return [yTG, mTG1, dTG, hTG1]
def gangzhi(year, month, day, hour, minute):
if hour == 23:
d = ephem.Date(round((ephem.Date("{}/{}/{} {}:00:00.00".format(
str(year).zfill(4),
str(month).zfill(2),
str(day+1).zfill(2),
str(0).zfill(2)))),3))
else:
d = ephem.Date("{}/{}/{} {}:00:00.00".format(
str(year).zfill(4),
str(month).zfill(2),
str(day).zfill(2),
str(hour).zfill(2)))
dd = list(d.tuple())
cdate = fromSolar(dd[0], dd[1], dd[2])
yTG,mTG,dTG,hTG = "{}{}".format(
tian_gan[cdate.getYearGZ().tg],
di_zhi[cdate.getYearGZ().dz]), "{}{}".format(
tian_gan[cdate.getMonthGZ().tg],
di_zhi[cdate.getMonthGZ().dz]), "{}{}".format(
tian_gan[cdate.getDayGZ().tg],
di_zhi[cdate.getDayGZ().dz]), "{}{}".format(
tian_gan[cdate.getHourGZ(dd[3]).tg],
di_zhi[cdate.getHourGZ(dd[3]).dz])
if year < 1900:
mTG1 = find_lunar_month(yTG).get(lunar_date_d(year, month, day).get("月"))
else:
mTG1 = mTG
hTG1 = find_lunar_hour(dTG).get(hTG[1])
zi = gangzhi1(year, month, day, 0, 0)[3]
if minute < 10 and minute >=0:
reminute = "00"
if minute < 20 and minute >=10:
reminute = "10"
if minute < 30 and minute >=20:
reminute = "20"
if minute < 40 and minute >=30:
reminute = "30"
if minute < 50 and minute >=40:
reminute = "40"
if minute < 60 and minute >=50:
reminute = "50"
hourminute = str(hour)+":"+str(reminute)
gangzhi_minute = ke_jiazi_d(zi).get(hourminute)
return [yTG, mTG1, dTG, hTG1, gangzhi_minute]
#旬
def shun(gz):
d_value1 = dict(zip(di_zhi, list(range(1,13)))).get(gz[1])
d_value2 = dict(zip(tian_gan, list(range(1,11)))).get(gz[0])
shun_value = d_value1 - d_value2
if shun_value < 0:
shun_value = shun_value+12
return {0:"戊", 10:"己", 8:"庚", 6:"辛", 4:"壬", 2:"癸"}.get(shun_value)
#五虎遁,起正月
def find_lunar_month(year):
fivetigers = {
tuple(list('甲己')):'丙寅',
tuple(list('乙庚')):'戊寅',
tuple(list('丙辛')):'庚寅',
tuple(list('丁壬')):'壬寅',
tuple(list('戊癸')):'甲寅'
}
if multi_key_dict_get(fivetigers, year[0]) == None:
result = multi_key_dict_get(fivetigers, year[1])
else:
result = multi_key_dict_get(fivetigers, year[0])
return dict(zip(range(1,13),new_list(jiazi(), result)[:12]))
#五鼠遁,起子時
def find_lunar_hour(day):
fiverats = {
tuple(list('甲己')):'甲子',
tuple(list('乙庚')):'丙子',
tuple(list('丙辛')):'戊子',
tuple(list('丁壬')):'庚子',
tuple(list('戊癸')):'壬子'
}
if multi_key_dict_get(fiverats, day[0]) == None:
result = multi_key_dict_get(fiverats, day[1])
else:
result = multi_key_dict_get(fiverats, day[0])
return dict(zip(list(di_zhi), new_list(jiazi(), result)[:12]))
#五馬遁,起子刻
def find_lunar_ke(hour):
fivehourses = {
tuple(list('丙辛')):'甲午',
tuple(list('丁壬')):'丙午',
tuple(list('戊癸')):'戊午',
tuple(list('甲己')):'庚午',
tuple(list('乙庚')):'壬午'
}
if multi_key_dict_get(fivehourses, hour[0]) == None:
result = multi_key_dict_get(fivehourses, hour[1])
else:
result = multi_key_dict_get(fivehourses, hour[0])
return new_list(jiazi(), result)
def liujiashun_dict():
jz = jiazi()[0::10]
jzlist = list(map(lambda x:new_list(jiazi(), x)[0:10],jz))
nlist = list(map(lambda x: tuple(x), jzlist))
return dict(zip(nlist, jiazi()[0::10]))
def findyuen_dict():
jz = jiazi()[0::5]
jzlist = list(map(lambda i:new_list(jiazi(), i)[0:5],jz))
nlist = list(map(lambda x:tuple(x), jzlist))
return dict(zip(nlist, ["上元","中元","下元"]*4))
#分干支
def minutes_jiazi_d():
t = [f"{h}:{m}" for h in range(24) for m in range(60)]
minutelist = dict(zip(t, cycle(repeat_list(2, jiazi()))))
return minutelist
def ke_jiazi_d(hour):
t = [f"{h}:{m}0" for h in range(24) for m in range(6)]
minutelist = dict(zip(t, cycle(repeat_list(1, find_lunar_ke(hour)))))
return minutelist
#農曆
def lunar_date_d(year, month, day):
lunar_m = ['占位', '正月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '冬月', '腊月']
day = fromSolar(year, month, day)
return {"年":day.getLunarYear(),
"農曆月": lunar_m[int(day.getLunarMonth())],
"月":day.getLunarMonth(),
"日":day.getLunarDay()}
#日空時空
def daykong_shikong(year, month, day, hour, minute):
guxu = {'甲子':{'孤':'戌亥', '虛':'辰巳'},
'甲戌':{'孤':'申酉', '虛':'寅卯'},
'甲申':{'孤':'午未', '虛':'子丑'},
'甲午':{'孤':'辰巳', '虛':'戌亥'},
'甲辰':{'孤':'寅卯', '虛':'申酉'},
'甲寅':{'孤':'子丑', '虛':'午未'}}
gz=gangzhi(year, month, day, hour, minute)
dk = multi_key_dict_get(liujiashun_dict(), gz[2])
sk = multi_key_dict_get(liujiashun_dict(), gz[3])
daykong = multi_key_dict_get(guxu, dk).get("孤")
shikong = multi_key_dict_get(guxu, sk).get("孤")
return {"日空":daykong,
"時空":shikong}
def hourkong_minutekong(year, month, day, hour, minute):
gz=gangzhi(year, month, day, hour, minute)
g3 = multi_key_dict_get(liujiashun_dict(), gz[3])
g4 = multi_key_dict_get(liujiashun_dict(), gz[4])
guxu = {'甲子':{'孤':'戌亥', '虛':'辰巳'},
'甲戌':{'孤':'申酉', '虛':'寅卯'},
'甲申':{'孤':'午未', '虛':'子丑'},
'甲午':{'孤':'辰巳', '虛':'戌亥'},
'甲辰':{'孤':'寅卯', '虛':'申酉'},
'甲寅':{'孤':'子丑', '虛':'午未'}}
daykong = multi_key_dict_get(guxu, g3).get("孤")
shikong = multi_key_dict_get(guxu, g4).get("孤")
return {"日空":daykong, "時空":shikong}
def find_shier_luck(gan):
cs = re.findall('..',"長生沐浴冠帶臨冠帝旺")
nlist = list(map(lambda i:new_list(di_zhi, i),list("亥寅寅巳申")))
nnlist = list(map(lambda i:new_list(di_zhi, i), list("亥寅寅巳申")))
cheungsunlist = list("死病衰") + re.findall('..',"帝旺臨冠冠帶沐浴長生") + list("養胎絕墓")
cslist2 = list(map(lambda y: dict(zip(y, cs + list("衰病死墓絕胎養"))), nlist))
cslist = [dict(zip(y, cheungsunlist)) for y in nnlist]
return {**dict(zip(tian_gan[0::2], cslist2)),
**dict(zip(tian_gan[1::2], cslist))}.get(gan)
#奇門排局拆補
def qimen_ju_name_chaibu(year, month, day, hour, minute):
yydun = {tuple(new_list(jieqi_name, "冬至")[0:12]):"陽遁",
tuple(new_list(jieqi_name, "夏至")[0:12]):"陰遁" }
jieqi = jq(year, month, day, hour, minute)
find_yingyang = multi_key_dict_get(yydun, jieqi)
find_yuen = findyuen(year, month, day, hour, minute)
jieqi_code = jieqicode(year, month, day, hour, minute)
return "{}{}局{}".format(find_yingyang,{
"上元":jieqi_code[0],
"中元":jieqi_code[1],
"下元":jieqi_code[2]}.get(find_yuen),
find_yuen)
#奇門排局置閏除虫用
def qimen_ju_name_zhirun_raw(year, month, day, hour, minute):
Jieqi = jq(year, month, day, hour, minute)
jlist = split_list(jiazi(), 5)
new_jq = new_list(jieqi_name, Jieqi)[1]
new_jq1 = new_list(jieqi_name, Jieqi)[0]
new_jq2 = new_list(jieqi_name, Jieqi)[-1]
jlist = [tuple(i) for i in jlist]
fuhead = dict(zip(jlist, jiazi()[0::5]))
yy = {tuple(new_list(jieqi_name, "冬至")[0:12]):"陽遁",
tuple(new_list(jieqi_name, "夏至")[0:12]):"陰遁" }
yin_yang = multi_key_dict_get(yy,new_jq1)
jieqi_code = jieqicode(year, month, day, hour, minute)
hgz = gangzhi(year, month, day, hour, minute)[3][0]
dgz = gangzhi(year, month, day, hour, minute)[2]
fd = multi_key_dict_get(fuhead, dgz)
zftg = zhifu_tiangan(year, month, day, hour, minute)
ju_day_dict = {tuple(["甲子","甲午","己卯","己酉"]):"上元",
tuple(["甲寅","甲申","己巳","己亥"]):"中元",
tuple(["甲辰","甲戌","己丑","己未"]):"下元"}
three_yuen = multi_key_dict_get(ju_day_dict, fd)
Jieqi_disance = jq_distance(year, month, day, hour, minute)[0].get(Jieqi)
current = jq_distance(year, month, day, hour, minute)[1]
current_ts = datetime.datetime.strptime(current, "%Y/%m/%d %H:%M:%S")
jq_distance_ts = datetime.datetime.strptime(Jieqi_disance,"%Y/%m/%d %H:%M:%S")
difference = (current_ts-jq_distance_ts).days
kooks = {"上元":jieqi_code[0],
"中元":jieqi_code[1],
"下元":jieqi_code[2]}.get(three_yuen)
jieqi_code1 = jieqicode_jq(new_jq)
jieqi_code2 = jieqicode_jq(new_jq1)
jieqi_code0 = jieqicode_jq(new_jq2)
kooks1 = {"上元":jieqi_code1[0],
"中元":jieqi_code1[1],
"下元":jieqi_code1[2]}.get(three_yuen)
kooks2 = {"上元":jieqi_code2[0],
"中元":jieqi_code2[1],
"下元":jieqi_code2[2]}.get(three_yuen)
kooks3 = {"上元":jieqi_code0[0],
"中元":jieqi_code0[1],
"下元":jieqi_code0[2]}.get(three_yuen)
lr = lunar_date_d(year, month, day)
return {"日期時間":"{}年{}月{}日{}時{}分".format(year, month, day, hour, minute),
"農曆": lr,
"節氣":Jieqi,
"距節氣差日數":difference,
"三元":three_yuen,
"當前節氣日期":Jieqi_disance,
"值符天干":zftg,
"節氣排局":jieqi_code2,
"陰陽局": yin_yang,
"當前排局":"{}{}局".format(yin_yang, kooks2),
"超神接氣正授排局":"{}{}局".format(multi_key_dict_get(yy,new_jq), kooks1),
"其他排局":"{}{}局".format(yin_yang, kooks3),
"其他排局1":"{}{}局".format(multi_key_dict_get(yy,new_jq), kooks),
}
#奇門排局置閏,正授,有超神,有閏奇,有接氣
def qimen_ju_name_zhirun(year, month, day, hour, minute):
qdict = qimen_ju_name_zhirun_raw(year, month, day, hour, minute)
jQ = qdict.get("節氣")
d = qdict.get("距節氣差日數")
tgft = qimen_ju_name_zhirun_raw(year, month, day, hour, minute).get("值符天干")
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月")<= 6 and lunar_date_d(year, month, day).get("農曆月") != "正月" and tgft not in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("日") > 20 and lunar_date_d(year, month, day).get("月") < 7 and lunar_date_d(year, month, day).get("農曆月") != "正月" and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("日") > 10 and lunar_date_d(year, month, day).get("月") < 7 and lunar_date_d(year, month, day).get("農曆月") != "正月" and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") >= 7 and lunar_date_d(year, month, day).get("農曆月") != "正月" and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") >=6 and lunar_date_d(year, month, day).get("農曆月") == "正月" :
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") == "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月":
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") == "冬月" and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") >= 15 and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") >= 15 and tgft != "己" and tgft != "戊" and tgft != "庚" and tgft != "壬" and tgft != "癸":
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") < 15 :
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") >= 20 :
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d > 6 and d <=9 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") < 10 :
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
#若距節氣差日數等於0或9天
if d == 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") > 9:
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d == 0 and lunar_date_d(year, month, day).get("農曆月") == "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月":
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d == 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月":
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
#若距節氣差日數介於10至15天
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") > 9:
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") != "正月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") < 15 :
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") == "正月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") < 15 :
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") != "正月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") >= 15 :
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") == "正月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") >= 15 :
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") == "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and jQ == "冬至":
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d >= 10 and d <= 15 and lunar_date_d(year, month, day).get("農曆月") == "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and jQ != "冬至":
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
if d >= 10 and d <= 12 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") == "冬月":
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d >= 12 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") == "冬月":
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
#若距節氣差日數少或等於6天
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") >= 9 and lunar_date_d(year, month, day).get("日") < 15 :
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") >= 9 and lunar_date_d(year, month, day).get("日") >= 15 and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") >= 9 and lunar_date_d(year, month, day).get("日") >= 15 and tgft not in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") < 9 and lunar_date_d(year, month, day).get("日") >= 15 and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") < 9 and lunar_date_d(year, month, day).get("日") >= 15 and tgft not in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") != "正月"and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") < 10 and tgft in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") == "正月" and lunar_date_d(year, month, day).get("月") <= 9 and lunar_date_d(year, month, day).get("日") < 10 and tgft not in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("月") <= 9 and tgft not in list("戊己庚辛壬癸"):
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") == "正月" and tgft in list("戊己庚辛壬癸") and lunar_date_d(year, month, day).get("日") < 20:
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") == "正月" and tgft in list("戊己庚辛壬癸") and lunar_date_d(year, month, day).get("日") > 20 and lunar_date_d(year, month, day).get("日") <= 26:
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" and lunar_date_d(year, month, day).get("農曆月") == "正月" and tgft in list("戊己庚辛壬癸") and lunar_date_d(year, month, day).get("日") > 26:
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") == "冬月" and jQ == "冬至" and d <3:
return "{}{}".format(qdict.get('其他排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") != "腊月" and lunar_date_d(year, month, day).get("農曆月") == "冬月" and jQ == "冬至":
return "{}{}".format(qdict.get('當前排局'), qdict.get('三元'))
if d <= 6 and d != 0 and lunar_date_d(year, month, day).get("農曆月") == "腊月" and lunar_date_d(year, month, day).get("農曆月") != "冬月" :
return "{}{}".format(qdict.get('其他排局1'), qdict.get('三元'))
else:
return "{}{}".format(qdict.get('超神接氣正授排局'), qdict.get('三元'))
#奇門排局刻家
def qimen_ju_name_ke(year, month, day, hour, minute):
hgz = gangzhi(year, month, day, hour, minute)[3]
find_yingyang = multi_key_dict_get({tuple(list('子丑寅卯辰巳')):"陽遁",
tuple(list('午未申酉戌亥')):"陰遁" },
hgz[1])
qu = {"陽遁":multi_key_dict_get({tuple(new_list(jieqi_name,"冬至")[0:12]):"一七四",
tuple(new_list(jieqi_name,"夏至")[0:12]):"一七四"},
jq(year,month, day,hour, minute)),
"陰遁":multi_key_dict_get({tuple(new_list(jieqi_name,"冬至")[0:12]):"九三六",
tuple(new_list(jieqi_name,"夏至")[0:12]):"九三六"},
jq(year,month, day,hour, minute))}.get(find_yingyang)
find_yuen = findyuen_minute(year, month, day, hour, minute)
return "{}{}局{}".format(find_yingyang, qu[dict(zip(["上元","中元","下元"],
[0,1,2])).get(find_yuen)],
find_yuen)
def getgtw():
gtw = re.findall("..","地籥六賊五符天曹地符風伯雷公雨師風雲唐符國印天關")
gg = re.findall("..","地籥天關唐符風雲唐符風雲雷公風伯天曹五符")
newmap = list(map(lambda i: new_list(gtw, i),gg))
newgtw_list = list(map(lambda y: dict(zip(di_zhi,y)),newmap))
return dict(zip(tian_gan, newgtw_list))
def pan_earth_minute(year, month, day, hour, minute):
"""刻家奇門地盤設置"""
ke = qimen_ju_name_ke(year,
month,
day,
hour,
minute)
return dict(zip(list(map(lambda x: dict(zip(cnumber, eight_gua)).get(x),
new_list(cnumber, ke[2]))),
{"陽遁":list("戊己庚辛壬癸丁丙乙"),
"陰遁":list("戊乙丙丁癸壬辛庚己")}.get(ke[0:2])))
def pan_earth_min_r(year, month, day, hour, minute):
"""刻家奇門地盤(逆)設置"""
pan_earth_v = list(pan_earth_minute(year, month, day, hour, minute).values())
pan_earth_k = list(pan_earth_minute(year, month, day, hour, minute).keys())
return dict(zip(pan_earth_v, pan_earth_k))
#排值符
def zhifu_pai(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
yinyang = qmju[0]
kook = qmju[2]
pai = {"陽":{"一":"九八七一二三四五六",
"二":"一九八二三四五六七",
"三":"二一九三四五六七八",
"四":"三二一四五六七八九",
"五":"四三二五六七八九一",
"六":"五四三六七八九一二",
"七":"六五四七八九一二三",
"八":"七六五八九一二三四",
"九":"八七六九一二三四五"},
"陰":{"九":"一二三九八七六五四",
"八":"九一二八七六五四三",
"七":"八九一七六五四三二",
"六":"七八九六五四三二一",
"五":"六七八五四三二一九",
"四":"五六七四三二一九八",
"三":"四五六三二一九八七",
"二":"三四五二一九八七六",
"一":"二三四一九八七六五"}}.get(yinyang).get(kook)
yinlist = list(map(lambda x: x+pai, new_list_r(cnumber, kook)[0:6]))
yanglist = list(map(lambda x: x+pai, new_list(cnumber, kook)[0:6]))
return {"陰":dict(zip(jiazi()[0::10], yinlist)),
"陽":dict(zip(jiazi()[0::10], yanglist))}.get(yinyang)
def zhifu_pai_ke(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
yinyang = qmju[0]
kook = qmju[2]
pai = {"陽":{"一":"九八七一二三四五六",
"二":"一九八二三四五六七",
"三":"二一九三四五六七八",
"四":"三二一四五六七八九",
"五":"四三二五六七八九一",
"六":"五四三六七八九一二",
"七":"六五四七八九一二三",
"八":"七六五八九一二三四",
"九":"八七六九一二三四五"},
"陰":{"九":"一二三九八七六五四",
"八":"九一二八七六五四三",
"七":"八九一七六五四三二",
"六":"七八九六五四三二一",
"五":"六七八五四三二一九",
"四":"五六七四三二一九八",
"三":"四五六三二一九八七",
"二":"三四五二一九八七六",
"一":"二三四一九八七六五"}}.get(yinyang).get(kook)
new_kook = new_list(cnumber, kook)
new_rkook = new_list_r(cnumber, kook)
yinlist = list(map(lambda x: x+pai, new_rkook[0:6]))
yanglist = list(map(lambda x: x+pai, new_kook[0:6]))
return {"陰":dict(zip(jiazi()[0::10], yinlist)),
"陽":dict(zip(jiazi()[0::10], yanglist))}.get(yinyang)
#1拆補 #2置閏
def zhishi_pai(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
yinyang = qmju[0]
kook = qmju[2]
new_kook = new_list(cnumber, kook)
new_rkook = new_list_r(cnumber, kook)
yanglist = "".join(new_kook)+"".join(new_kook)+"".join(new_kook)
yinlist = "".join(new_rkook)+"".join(new_rkook)+"".join(new_rkook)
yinlist1 = list(map(lambda i:i+yinlist[yinlist.index(i)+1:][0:11],new_rkook[0:6]))
yanglist1 = list(map(lambda i:i+yanglist[yanglist.index(i)+1:][0:11],new_kook[0:6]))
return {"陰":dict(zip(jiazi()[0::10], yinlist1)),
"陽":dict(zip(jiazi()[0::10], yanglist1))}.get(yinyang)
def zhishi_pai_ke(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
yinyang = qmju[0]
kook = qmju[2]
new_kook = new_list(cnumber, kook)
new_rkook = new_list_r(cnumber, kook)
yanglist = "".join(new_kook)+"".join(new_kook)+"".join(new_kook)
yinlist = "".join(new_rkook)+"".join(new_rkook)+"".join(new_rkook)
yinlist1 = list(map(lambda i:i+ yinlist[yinlist.index(i)+1:][0:11],new_rkook[0:6]))
yanglist1 = list(map(lambda i:i+ yanglist[yanglist.index(i)+1:][0:11],new_kook[0:6]))
return {"陰":dict(zip(jiazi()[0::10], yinlist1)),
"陽":dict(zip(jiazi()[0::10], yanglist1))}.get(yinyang)
#八門
def pan_door(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
zfnzs = zhifu_n_zhishi(year, month, day, hour, minute, option)
starting_door = zfnzs.get("值使門宮")[0]
starting_gong = zfnzs.get("值使門宮")[1]
rotate = {"陽":clockwise_eightgua,
"陰":list(reversed(clockwise_eightgua))}.get(qmju[0])
if starting_gong == "中":
gong_reorder = new_list(rotate, "坤")
else:
gong_reorder = new_list(rotate, starting_gong)
yydoor = {"陽":new_list(door_r, starting_door),
"陰":new_list(list(reversed(door_r)), starting_door)}
return dict(zip(gong_reorder,yydoor.get(qmju[0])))
def pan_door_minute(year, month, day, hour, minute, option):
qimen_ke = qimen_ju_name_ke(year, month, day, hour, minute)
zhifu_n_zhishike = zhifu_n_zhishi_ke(year, month, day, hour, minute)
starting_door = zhifu_n_zhishike.get("值使門宮")[0]
starting_gong = zhifu_n_zhishike.get("值使門宮")[1]
rotate = {"陽":clockwise_eightgua,
"陰":list(reversed(clockwise_eightgua))}.get(qimen_ke[0])
if starting_gong == "中":
gong_reorder = new_list(rotate, "坤")
else:
gong_reorder = new_list(rotate, starting_gong)
yydict = {"陽":new_list(door_r, starting_door),
"陰":new_list(list(reversed(door_r)), starting_door)}
return dict(zip(gong_reorder,yydict.get(qimen_ke[0])))
#九星
def pan_star(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
zhifunzhishi = zhifu_n_zhishi(year, month, day, hour, minute, option)
star_r = list("蓬任沖輔英禽柱心")
starting_star = zhifunzhishi.get("值符星宮")[0].replace("芮", "禽")
starting_gong = zhifunzhishi.get("值符星宮")[1]
rotate = {"陽":clockwise_eightgua,
"陰":list(reversed(clockwise_eightgua))}.get(qmju[0])
star_reorder = {"陽":new_list(star_r, starting_star),
"陰":new_list(list(reversed(star_r)), starting_star)}.get(qmju[0])
if starting_gong == "中":
gong_reorder = new_list(rotate, "坤")
else:
gong_reorder = new_list(rotate, starting_gong)
return dict(zip(gong_reorder,star_reorder)), dict(zip(star_reorder, gong_reorder))
def pan_star_minute(year, month, day, hour, minute, option):
star_r = list("蓬任沖輔英禽柱心")
zhifu_n_zhishi = zhifu_n_zhishi_ke(year, month, day, hour, minute)
qimen_ke = qimen_ju_name_ke(year, month, day, hour, minute)
starting_star = zhifu_n_zhishi.get("值符星宮")[0].replace("芮", "禽")
starting_gong = zhifu_n_zhishi.get("值符星宮")[1]
qmke = qimen_ju_name_ke(year, month, day, hour, minute)
rotate = {"陽":clockwise_eightgua,
"陰":list(reversed(clockwise_eightgua))}.get(qimen_ke[0])
star_reorder = {"陽":new_list(star_r, starting_star),
"陰":new_list(list(reversed(star_r)),starting_star)}.get(qmke[0])
if starting_gong == "中":
gong_reorder = new_list(rotate, "坤")
else:
gong_reorder = new_list(rotate, starting_gong)
return dict(zip(gong_reorder,star_reorder)), dict(zip(star_reorder, gong_reorder))
#八神
def pan_god(year, month, day, hour, minute, option):
qmju = {1:qimen_ju_name_chaibu(year, month, day, hour, minute),
2:qimen_ju_name_zhirun(year, month, day, hour, minute)}.get(option)
zfzs = zhifu_n_zhishi(year, month, day, hour, minute, option)
starting_gong = zfzs.get("值符星宮")[1]
rotate = {"陽":clockwise_eightgua,
"陰":list(reversed(clockwise_eightgua))}.get(qmju[0])
if starting_gong == "中":
gong_reorder = new_list(rotate, "坤")
else:
gong_reorder = new_list(rotate, starting_gong)
return dict(zip(gong_reorder,{"陽":list("符蛇陰合勾雀地天"),
"陰":list("符蛇陰合虎玄地天")}.get(qmju[0])))
def pan_god_minute(year, month, day, hour, minute, option):
zfzs = zhifu_n_zhishi_ke(year, month, day, hour, minute)
starting_gong = zfzs.get("值符星宮")[1]
qmke = qimen_ju_name_ke(year, month, day, hour, minute)
rotate = {"陽":clockwise_eightgua,
"陰":list(reversed(clockwise_eightgua))}.get(qmke[0])
if starting_gong == "中":
gong_reorder = new_list(rotate, "坤")
else:
gong_reorder = new_list(rotate, starting_gong)
return dict(zip(gong_reorder,{"陽":list("符蛇陰合勾雀地天"),
"陰":list("符蛇陰合虎玄地天")}.get(qmke[0])))
#找值符及值使
def zhifu_n_zhishi(year, month, day, hour, minute, option):
gongs_code = dict(zip(cnumber, eight_gua))
gz = gangzhi(year, month, day, hour, minute)
hgan = dict(zip(tian_gan,range(0,11))).get(gz[3][0])
chour = multi_key_dict_get(liujiashun_dict(), gz[3])
eg = list("休死傷杜中開驚生景")
eight_gods = list("蓬芮沖輔禽心柱任英")
zspai_keys = list(zhishi_pai(year, month, day, hour, minute, option).keys())
zspai_values = list(zhishi_pai(year, month, day, hour, minute, option).values())
zf_keys = list(zhifu_pai(year, month, day, hour, minute, option).keys())
zf_values = list(zhifu_pai(year, month, day, hour, minute, option).values())
a = list(map(lambda i: dict(zip(cnumber, eg)).get(i[0]), zspai_values))
b = list(map(lambda i:dict(zip(cnumber, eight_gods)).get(i[0]) , zf_values))
c = list(map(lambda i:gongs_code.get(i[hgan]), zf_values))
d = list(map(lambda i:gongs_code.get(i[hgan]), zspai_values))
door = dict(zip(zspai_keys, a)).get(chour)
if door == "中":
door = "死"
return {"值符天干": [chour, jj.get(chour)],
"值符星宮":[dict(zip(zf_keys, b)).get(chour),dict(zip(zf_keys, c)).get(chour)],
"值使門宮":[door,dict(zip(zspai_keys,d)).get(chour)]}
def zhifu_tiangan(year, month, day, hour, minute):
gz = gangzhi(year, month, day, hour, minute)
jj = {"甲子":"戊","甲戌":"己","甲申":"庚","甲午":"辛","甲辰":"壬","甲寅":"癸"}
chour = multi_key_dict_get(liujiashun_dict(), gz[3])
return jj.get(chour)
def zhifu_n_zhishi_ke(year, month, day, hour, minute):
gz = gangzhi(year, month, day, hour, minute)
qmke = qimen_ju_name_ke(year, month, day, hour, minute)
chour = multi_key_dict_get(liujiashun_dict(),gz[4])
#chour2 = multi_key_dict_get(liujiashun_dict(),gz[3])
ep = pan_earth_min_r(year, month, day, hour, minute)
zftg = {"甲子":"戊","甲戌":"己","甲申":"庚","甲午":"辛","甲辰":"壬","甲寅":"癸"}.get(multi_key_dict_get(liujiashun_dict(), gz[4]))
kook = re.findall("..", "陽一陽四陽七陰九陰六陰三")
liujia = re.findall("..", "甲子甲戌甲申甲午甲辰甲寅")
stars = [list("蓬芮沖輔禽心"), list("輔禽心柱任英"), list("柱任英蓬芮沖"), list("英任柱心禽輔"), list("心禽輔沖芮蓬"), list("沖芮蓬英任柱")]
doors = [re.findall("..", "休坎死坤傷震杜巽死中開乾"),
re.findall("..", "杜巽死中開乾驚兌生艮景離"),
re.findall("..", "驚兌生艮景離休坎死坤傷震"),
re.findall("..", "景離生艮驚兌開乾死中杜巽"),
re.findall("..", "開乾死中杜巽傷震死坤休坎"),
re.findall("..", "傷震死坤休坎景離生艮驚兌")]
stars_zhifu = {kook[i]: {liujia[j]: stars[i][j] for j in range(len(liujia))} for i in range(len(kook))}.get("{}{}".format(qmke[0], qmke[2])).get(chour)
shi_door = {kook[i]: {liujia[j]:doors[i][j] for j in range(len(liujia))} for i in range(len(kook))}.get("{}{}".format(qmke[0], qmke[2])).get(chour)[0]
shi_door_head = {kook[i]: {liujia[j]:doors[i][j] for j in range(len(liujia))} for i in range(len(kook))}.get("{}{}".format(qmke[0], qmke[2])).get(chour)[1]
fiftheen_ke_gz = new_list(jiazi(), chour)[0:16]
door_order ={"陽":new_list(eight_gua, shi_door_head), "陰": new_list(list(reversed(eight_gua)), shi_door_head)}.get(qmke[0])
fu = ep.get(gz[4][0])
if fu == None:
fu = ep.get(zftg)
zhifu_star = [stars_zhifu, fu]
zhifu_door = [shi_door,dict(zip(fiftheen_ke_gz, cycle(door_order))).get(gz[4])]
return {"值符天干":zftg, "值符星宮":zhifu_star, "值使門宮":zhifu_door}
def gong_wangzhuai():
wangzhuai = list("旺相胎沒死囚休廢")
wangzhuai_num = [3,4,9,2,7,6,1,8]
wangzhuai_jieqi = {('春分','清明','穀雨'):'春分',
('立夏','小滿','芒種'):'立夏',
('夏至','小暑','大暑'):'夏至',
('立秋','處暑','白露'):'立秋',
('秋分','寒露','霜降'):'秋分',
('立冬','小雪','大雪'):'立冬',
('冬至','小寒','大寒'):'冬至',
('立春','雨水','驚蟄'):'立春'}
wzhuai = multi_key_dict_get(wangzhuai_jieqi, "霜降")
wz = dict(zip(jieqi_name[0::3],wangzhuai_num)).get(wzhuai)
new_dict = new_list(wangzhuai_num, wz)
return dict(zip(new_dict, wangzhuai))
def ecliptic_lon(jd_utc):
s=ephem.Sun(jd_utc)
equ=ephem.Equatorial(s.ra,s.dec,epoch=jd_utc)
e=ephem.Ecliptic(equ)
return e.lon
def sta(jd):
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)
return n
def iteration(jd,sta):
s1=sta(jd)
s0=s1
dt=1.0
while True:
jd+=dt
s=sta(jd)
if s0!=s:
s0=s
dt=-dt/2
if abs(dt)<0.0000001 and s!=s1:
break
return jd
def change(year, month, day, hour, minute):
changets = ephem.Date("{}/{}/{} {}:{}:00".format(str(year).zfill(4),
str(month).zfill(2),
str(day).zfill(2),
str(hour).zfill(2),
str(minute).zfill(2)))
return ephem.Date(changets - 24 * ephem.hour *30)
def jq(year, month, day, hour, minute):
current = ephem.Date("{}/{}/{} {}:{}:00".format(str(year).zfill(4),
str(month).zfill(2),
str(day).zfill(2),
str(hour).zfill(2),
str(minute).zfill(2)))
jd = change(year, month, day, hour, minute)
result = []
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)+1
for i in range(3):
if n>=24:
n-=24
jd=iteration(jd,sta)
d=ephem.Date(jd+1/3).tuple()
dt = ephem.Date("{}/{}/{} {}:{}:00.00".format(d[0],
d[1],
d[2],
d[3],
d[4]).split(".")[0])
time_info = {dt:jieqi_name[n]}
n+=1
result.append(time_info)
j = [list(i.keys())[0] for i in result]
if current > j[0] and current > j[1] and current > j[2]:
return list(result[2].values())[0]
if current > j[0] and current > j[1] and current <= j[2]:
return list(result[1].values())[0]
if current >= j[1] and current < j[2]:
return list(result[1].values())[0]
if current < j[1] and current < j[2]:
return list(result[0].values())[0]
def jq_distance(year, month, day, hour, minute):
current = "{}/{}/{} {}:{}:00".format(str(year).zfill(4),
str(month).zfill(2),
str(day).zfill(2),str(hour).zfill(2),
str(minute).zfill(2))
jd = change(year, month, day, hour, minute)
result = {}
e=ecliptic_lon(jd)
n=int(e*180.0/math.pi/15)+1
for i in range(12):
if n>=24:
n-=24
jd=iteration(jd,sta)
d=ephem.Date(jd+1/3).tuple()
dt = "{}/{}/{} {}:{}:00.00".format(d[0],d[1],d[2],
str(d[3]).zfill(2),
str(d[4]).zfill(2)).split(".")[0]
time_info = {jieqi_name[n]:dt}
n+=1
result.update(time_info)
return result, current
#刻家奇門 五行旺衰
def wuxing_strong_week_minute(jq):
j = new_list(jieqi_name, "小寒")
sw = list("旺相休囚死")
fs_order = ["土金火木水",
"土金火木水",
"木火水金土",
"木火水金土",
"木火水金土",
"木火水金土",
"土金火木水",
"土金火木水",
"火土木水金",
"火土木水金",
"火土木水金",
"火土木水金",
"土金火木水",
"土金火木水",
"金水土火木",
"金水土火木",
"金水土火木",
"金水土火木",
"土金火木水",
"土金火木水",
"水木金土火",
"水木金土火",
"水木金土火",
"水木金土火"]
fs_list = [dict(zip(i,sw)) for i in fs_order]
return dict(zip(j, fs_list)).get(jq)
#五行旺衰
def wuxing_strong_week(jq):
season = find_season(jq)
sw = list("旺相休囚死")
fs = list("春夏秋冬")
fs_order = ["木火水金土",
"火土木水金",
"金水土火木",
"水木金土火"]
fs_list = [dict(zip(i,sw)) for i in fs_order]
return dict(zip(fs, fs_list)).get(season)
def pan_sky_minute(year, month, day, hour, minute ):
"""刻家奇門天盤設置"""
zfzs = zhifu_n_zhishi_ke(year, month, day, hour, minute)
zftg = zfzs.get("值符天干")
zfgong = zfzs.get("值符星宮")[1]
eg = list("坎坤震巽乾兌艮離")
kook_setting = [tuple(["陰三","陽七"]),tuple(["陽四","陰六"]), tuple(["陰九","陽一"])]
skypan_orders = [[
list("戊丁辛己丙壬庚乙癸"),
list("己戊丁庚丙辛乙癸壬"),
list("庚己戊乙丙丁癸壬辛"),
list("丁辛壬戊丙癸己庚乙"),
list("乙庚己癸丙戊壬辛丁"),
list("辛壬癸丁丙乙戊己庚"),
list("壬癸乙辛丙庚丁戊己"),
list("癸乙庚壬丙己辛丁戊")
],[
list("戊丁丙辛己乙壬癸庚"),
list("辛戊丁壬己丙癸庚乙"),
list("壬辛戊癸己丁庚乙丙"),
list("丁丙乙戊己庚辛壬癸"),
list("癸壬辛庚己戊乙丙丁"),
list("丙乙庚丁己癸戊辛壬"),
list("乙庚癸丙己壬丁戊辛"),
list("庚癸壬乙己辛丙丁戊")
],[
list("戊己庚辛壬癸丁丙乙"),
list("辛戊己丁壬庚丙乙癸"),
list("丁辛戊丙壬己乙癸庚"),
list("己庚癸戊壬乙辛丁丙"),
list("丙丁辛乙壬戊癸庚己"),
list("庚癸乙己壬丙戊辛丁"),
list("癸乙丙庚壬丁己戊辛"),
list("乙丙丁癸壬辛庚己戊"),
]]
sky_pan_orders = dict(zip(kook_setting, skypan_orders))
liujia = list("戊己庚辛壬癸")
orders = [[[0,1,2,3,1,4,5,6,7],[1,2,4,0,2,7,3,5,6],[2,4,7,1,4,6,0,3,5],[5,3,0,6,3,1,7,4,2],[6,5,3,7,5,0,4,2,1],[7,6,5,4,6,3,2,1,0]],
[[0,1,2,3,1,4,5,6,7],[5,3,0,6,3,1,7,4,2],[7,6,5,4,6,3,2,1,0],[1,2,4,0,2,7,3,5,6],[2,4,7,1,4,6,0,3,5],[4,7,6,2,7,5,1,0,3]],
[[0,1,2,3,1,4,5,6,7],[3,0,1,5,0,2,6,7,4],[5,3,0,6,3,1,7,4,2],[1,2,4,0,2,7,3,5,6],[3,0,1,5,0,2,6,7,4],[6,5,3,7,5,0,4,2,1]]]
get_zf_orders = dict(zip(kook_setting, orders))
ke = qimen_ju_name_ke(year, month, day, hour, minute)
kook = "{}{}".format(ke[0],ke[2])
getzf_orders = multi_key_dict_get(get_zf_orders, kook)
get_humhead = dict(zip(liujia, getzf_orders)).get(zftg)
return dict(zip(eight_gua,multi_key_dict_get(sky_pan_orders, kook)[dict(zip(eight_gua, get_humhead)).get(zfgong)]))#, getzf_orders, get_humhead
#暗干
angan ={"陽四":{
"甲子":{"坎":"庚午","坤":"辛未","震":"壬申","巽":"癸酉","中":"乙丑",
"乾":"丙寅","兌":"丁卯","艮":"戊辰","離":"己巳"},
"甲戌":{"坎":"己卯","坤":"庚辰","震":"辛巳","巽":"壬午","中":"癸未",
"乾":"乙亥","兌":"丙子","艮":"丁丑","離":"戊寅"},
"甲申":{"坎":"戊子","坤":"己丑","震":"庚寅","巽":"辛卯","中":"壬辰",
"乾":"癸巳","兌":"乙酉","艮":"丙戌","離":"丁亥"},
"甲午":{"坎":"丁酉","坤":"戊戌","震":"己亥","巽":"庚子","中":"辛丑",
"乾":"壬寅","兌":"癸卯","艮":"乙未","離":"丙申"},
"甲辰":{"坎":"丙午","坤":"丁未","震":"戊申","巽":"己酉","中":"庚戌",
"乾":"辛亥","兌":"壬子","艮":"癸丑","離":"乙巳"},
"甲寅":{"坎":"乙卯","坤":"丙辰","震":"丁巳","巽":"戊午","中":"己未",
"乾":"庚申","兌":"辛酉","艮":"壬戌","離":"癸亥"}},
"陽一":{
"甲子":{"坎":"癸酉","坤":"乙丑","震":"丙寅","巽":"丁卯","中":"戊辰",
"乾":"己巳","兌":"庚午","艮":"辛未","離":"壬申"},
"甲戌":{"坎":"壬午","坤":"癸未","震":"乙亥","巽":"丙子","中":"丁丑",
"乾":"戊寅","兌":"己卯","艮":"庚辰","離":"辛巳"},
"甲申":{"坎":"辛卯","坤":"壬辰","震":"癸巳","巽":"乙酉","中":"丙戌",
"乾":"丁亥","兌":"戊子","艮":"己丑","離":"庚寅"},
"甲午":{"坎":"庚子","坤":"辛丑","震":"壬寅","巽":"癸卯","中":"乙未",
"乾":"丙申","兌":"丁酉","艮":"戊戌","離":"己亥"},
"甲辰":{"坎":"己酉","坤":"庚戌","震":"辛亥","巽":"壬子","中":"癸丑",
"乾":"乙巳","兌":"丙午","艮":"丁未","離":"戊申"},
"甲寅":{"坎":"戊午","坤":"己末","震":"庚申","巽":"辛酉","中":"壬戌",
"乾":"癸亥","兌":"乙卯","艮":"丙辰","離":"丁巳"}},
"陽七":{
"甲子":{"坎":"丁卯","坤":"戊辰","震":"己巳","巽":"庚午","中":"辛未",
"乾":"壬申","兌":"癸酉","艮":"乙丑","離":"丙寅"},
"甲戌":{"坎":"丙子","坤":"丁丑","震":"戊寅","巽":"己卯","中":"庚辰",
"乾":"辛巳","兌":"壬午","艮":"癸未","離":"乙亥"},
"甲申":{"坎":"乙酉","坤":"丙戌","震":"丁亥","巽":"戊子","中":"己丑",
"乾":"庚寅","兌":"辛卯","艮":"壬辰","離":"癸巳"},
"甲午":{"坎":"癸卯","坤":"乙未","震":"丙申","巽":"丁酉","中":"戊戌",
"乾":"辛丑","兌":"庚子","艮":"己亥","離":"壬寅"},
"甲辰":{"坎":"壬子","坤":"癸丑","震":"乙巳","巽":"丙午","中":"丁未",
"乾":"戊申","兌":"己酉","艮":"庚戌","離":"辛亥"},
"甲寅":{"坎":"辛酉","坤":"壬戌","震":"癸亥","巽":"乙卯","中":"丙辰",
"乾":"丁巳","兌":"戊午","艮":"己未","離":"庚申"}},