-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathdemo.py
259 lines (206 loc) · 7.44 KB
/
demo.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
# -*- coding: utf-8 -*-
from lunar_python import Lunar, Solar
from lunar_python.util import HolidayUtil
from datetime import datetime
# 节气表
lunar = Solar.fromYmd(2022, 7, 15).getLunar()
jieQi = lunar.getJieQiTable()
for k in lunar.getJieQiList():
print(k + ' = ' + jieQi[k].toYmdHms())
print('')
# 八字
baZi = lunar.getEightChar()
print(baZi.getYear() + ' ' + baZi.getMonth() + ' ' + baZi.getDay() + ' ' + baZi.getTime())
# 八字五行
print(baZi.getYearWuXing() + ' ' + baZi.getMonthWuXing() + ' ' + baZi.getDayWuXing() + ' ' + baZi.getTimeWuXing())
# 八字天干十神
print(baZi.getYearShiShenGan() + ' ' + baZi.getMonthShiShenGan() + ' ' + baZi.getDayShiShenGan() + ' ' + baZi.getTimeShiShenGan())
# 八字地支十神
print(baZi.getYearShiShenZhi()[0] + ' ' + baZi.getMonthShiShenZhi()[0] + ' ' + baZi.getDayShiShenZhi()[0] + ' ' + baZi.getTimeShiShenZhi()[0])
# 遍历八字年支十神
for v in baZi.getYearShiShenZhi():
print(v)
print('')
# 遍历八字月支十神
for v in baZi.getMonthShiShenZhi():
print(v)
print('')
# 遍历八字日支十神
for v in baZi.getDayShiShenZhi():
print(v)
print('')
# 遍历八字时支十神
for v in baZi.getTimeShiShenZhi():
print(v)
print('')
solar = Solar(1988, 2, 15, 23, 30, 0)
lunar = solar.getLunar()
baZi = lunar.getEightChar()
print(baZi.getYear() + ' ' + baZi.getMonth() + ' ' + baZi.getDay() + ' ' + baZi.getTime())
solar = Solar(1983, 2, 15, 20, 0, 0)
lunar = solar.getLunar()
baZi = lunar.getEightChar()
# 女运
yun = baZi.getYun(0)
print('阳历' + solar.toYmdHms() + '出生')
print('出生' + str(yun.getStartYear()) + '年' + str(yun.getStartMonth()) + '个月' + str(yun.getStartDay()) + '天后起运')
print('阳历' + yun.getStartSolar().toYmd() + '后起运')
print('')
# 大运
daYunArr = yun.getDaYun()
for i in range(0, len(daYunArr)):
daYun = daYunArr[i]
print('大运[' + str(i) + '] ' + str(daYun.getStartYear()) + '年 ' + str(daYun.getStartAge()) + '岁 ' + daYun.getGanZhi())
print('')
# 大运[0] 流年
liuNianArr = daYunArr[0].getLiuNian()
for i in range(0, len(liuNianArr)):
liuNian = liuNianArr[i]
print('流年[' + str(i) + '] ' + str(liuNian.getYear()) + '年 ' + str(liuNian.getAge()) + '岁 ' + liuNian.getGanZhi())
print('')
# 大运[0] 小运
xiaoYunArr = daYunArr[0].getXiaoYun()
for i in range(0, len(xiaoYunArr)):
xiaoYun = xiaoYunArr[i]
print('小运[' + str(i) + '] ' + str(xiaoYun.getYear()) + '年 ' + str(xiaoYun.getAge()) + '岁 ' + xiaoYun.getGanZhi())
print('')
# 流年[0] 流月
liuYueArr = liuNianArr[0].getLiuYue()
for i in range(0, len(liuYueArr)):
liuYue = liuYueArr[i]
print('流月[' + str(i) + '] ' + str(liuYue.getMonthInChinese()) + '月 ' + liuYue.getGanZhi())
print('')
# 通过指定年月日初始化阴历
lunar = Lunar.fromYmd(1986, 4, 21)
# 打印阴历
print(lunar.toFullString())
# 阴历转阳历并打印
print(lunar.getSolar().toFullString())
# 节假日信息
print(HolidayUtil.getHoliday('2020-05-02'))
# 儒略日
solar = Solar.fromYmd(2020, 7, 15)
print(solar.getJulianDay())
solar = Solar.fromJulianDay(2459045.5)
print(solar.toYmdHms())
print('')
# 八字转阳历
for d in Solar.fromBaZi("庚子", "戊子", "己卯", "庚午"):
print(d.toFullString())
date = Solar.fromYmd(2020, 1, 23)
print("2020-01-24" == date.next(1).toString())
# 仅工作日,跨越春节假期
print("2020-02-03" == date.next(1, True).toString())
date = Solar.fromYmd(2020, 2, 3)
print("2020-01-31" == date.next(-3).toString())
# 仅工作日,跨越春节假期
print("2020-01-21" == date.next(-3, True).toString())
date = Solar.fromYmd(2020, 2, 9)
print("2020-02-15" == date.next(6).toString())
# 仅工作日,跨越周末
print("2020-02-17" == date.next(6, True).toString())
date = Solar.fromYmd(2020, 1, 17)
print("2020-01-18" == date.next(1).toString())
# 仅工作日,周日调休按上班算
print("2020-01-19" == date.next(1, True).toString())
print("2020-01-01 元旦节 2020-01-01" == HolidayUtil.getHoliday("2020-01-01").toString())
# 将2020-01-01修改为春节
HolidayUtil.fix(None, "202001011120200101")
print("2020-01-01 春节 2020-01-01" == HolidayUtil.getHoliday("2020-01-01").toString())
# 追加2099-01-01为元旦节
HolidayUtil.fix(None, "209901010120990101")
print("2099-01-01 元旦节 2099-01-01" == HolidayUtil.getHoliday("2099-01-01").toString())
# 将2020-01-01修改为春节,并追加2099-01-01为元旦节
HolidayUtil.fix(None, "202001011120200101209901010120990101")
print("2020-01-01 春节 2020-01-01" == HolidayUtil.getHoliday("2020-01-01").toString())
print("2099-01-01 元旦节 2099-01-01" == HolidayUtil.getHoliday("2099-01-01").toString())
# 更改节假日名称
names = []
for i in range(0, len(HolidayUtil.NAMES)):
names.append(HolidayUtil.NAMES[i])
names[0] = "元旦"
names[1] = "大年初一"
HolidayUtil.fix(names, None)
print("2020-01-01 大年初一 2020-01-01" == HolidayUtil.getHoliday("2020-01-01").toString())
print("2099-01-01 元旦 2099-01-01" == HolidayUtil.getHoliday("2099-01-01").toString())
# 追加节假日名称和数据
names = []
for i in range(0, len(HolidayUtil.NAMES)):
names.append(HolidayUtil.NAMES[i])
names.append("我的生日")
names.append("结婚纪念日")
names.append("她的生日")
HolidayUtil.fix(names, "20210529912021052920211111:12021111120211201;120211201")
print("2021-05-29 我的生日 2021-05-29" == HolidayUtil.getHoliday("2021-05-29").toString())
print("2021-11-11 结婚纪念日 2021-11-11" == HolidayUtil.getHoliday("2021-11-11").toString())
print("2021-12-01 她的生日 2021-12-01" == HolidayUtil.getHoliday("2021-12-01").toString())
# 节日
solar = Solar.fromYmd(2020, 11, 26)
festivals = solar.getFestivals()
for i in range(0, len(festivals)):
print(festivals[i])
solar = Solar.fromYmd(2020, 6, 21)
festivals = solar.getFestivals()
for i in range(0, len(festivals)):
print(festivals[i])
solar = Solar.fromYmd(2021, 5, 9)
festivals = solar.getFestivals()
for i in range(0, len(festivals)):
print(festivals[i])
solar = Solar.fromYmd(1986, 11, 27)
festivals = solar.getFestivals()
for i in range(0, len(festivals)):
print(festivals[i])
solar = Solar.fromYmd(1985, 6, 16)
festivals = solar.getFestivals()
for i in range(0, len(festivals)):
print(festivals[i])
solar = Solar.fromYmd(1984, 5, 13)
festivals = solar.getFestivals()
for i in range(0, len(festivals)):
print(festivals[i])
# 旬
solar = Solar.fromYmdHms(2020, 11, 19, 0, 0, 0)
lunar = solar.getLunar()
# 甲午
print(lunar.getYearXun())
# 旬空(空亡)
# 辰巳
print(lunar.getYearXunKong())
# 午未
print(lunar.getMonthXunKong())
# 戌亥
print(lunar.getDayXunKong())
# 八字日柱旬空(空亡)
solar = Solar.fromYmdHms(1990, 12, 23, 8, 37, 0)
lunar = solar.getLunar()
eightChar = lunar.getEightChar()
# 子丑
print(eightChar.getDayXunKong())
# 数九
lunar = Lunar.fromDate(datetime.now())
print(lunar.getShuJiu())
# 三伏
solar = Solar.fromYmd(2020, 8, 24)
lunar = solar.getLunar()
print(lunar.getFu().toFullString())
# 六曜
lunar = Lunar.fromDate(datetime.now())
print(lunar.getLiuYao())
# 物候
print(lunar.getWuHou())
# 日九星
print(lunar.getDayNineStar())
# 年太岁
print(lunar.getYearPositionTaiSui())
print(lunar.getYearPositionTaiSuiDesc())
# 月太岁
print(lunar.getMonthPositionTaiSui())
print(lunar.getMonthPositionTaiSuiDesc())
# 日太岁
print(lunar.getDayPositionTaiSui())
print(lunar.getDayPositionTaiSuiDesc())
times = lunar.getTimes()
for i in range(0, len(times)):
time = times[i]
print("%s - %s : %s" % (time.getMinHm(), time.getMaxHm(), time.toString()))