def init(self): __基准积日 = 708011105 __基准时间 = datetime.datetime.strptime("1900-12-21 00:00:00", "%Y-%m-%d %H:%M:%S") y = self.year m = self.month d = self.day __t = datetime.datetime.strptime( "{0:04}-{1:02d}-{2:02d} 00:00:00".format(y, m, d), "%Y-%m-%d %H:%M:%S") __积日 = __基准积日 + (__t - __基准时间).days __积时 = (__积日 - 1) * 12 + (self.hour + 1) // 2 + 1 self.积算 = __积时 c = eacal.EACal(zh_s=True) __年干支, __月干支, __日干支 = c.get_cycle_ymd(datetime.datetime(y, m, d)) __日干支 = 干支(干("癸"), 支("亥")) + __积日 % 60 if self.hour == 23: __日干支 = __日干支 + 1 __时干支 = 干支(干("癸"), 支("亥")) + __积时 % 60 siZhu = "{} {} {} {}".format(__年干支, __月干支, __日干支, __时干支) # 求空亡 __旬首 = __日干支.支 + (干("甲") - __日干支.干) siZhu = '{} (甲{}旬,<font color="red">{}、{}</font>空亡)'.format( siZhu, __旬首, __旬首 + (-2), __旬首 + (-1)) self.header = "{} <div>干支: {} </div> <div>时计太乙</div>".format( self.header, siZhu)
def init(self): # __基准积日 = 708011105 # __基准时间 = datetime.datetime.strptime("1900-12-21 00:00:00", # "%Y-%m-%d %H:%M:%S") __基准积日 = 0 __基准时间 = datetime.datetime.strptime("1900-06-19 00:00:00", "%Y-%m-%d %H:%M:%S") y = self.year m = self.month d = self.day __t = datetime.datetime.strptime( "{0:04}-{1:02d}-{2:02d} 00:00:00".format(y, m, d), "%Y-%m-%d %H:%M:%S") __积日 = __基准积日 + (__t - __基准时间).days self.积算 = __积日 c = eacal.EACal(zh_s=True) # print(c) __年干支, __月干支, __日干支 = c.get_cycle_ymd(datetime.datetime(y, m, d)) __日干支 = 干支(干("癸"), 支("亥")) + __积日 % 60 # __月干支 = 干支(干("甲"), 支("子")) + (__积算 % 60 - 1) self.header = "{} <div>干支: {} {} {}</div> <div>月计太乙</div>".format( self.header, __年干支, __月干支, __日干支)
def GetLi(y, m, d, h, minu, sec): timeString = "{0}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}".format( y, m, d, h, minu, sec) 占时Time = datetime.datetime.strptime(timeString, "%Y-%m-%d %H:%M:%S") 前一节Time = None 前一节Num = None 后一节Time = None 后一节Num = None c = eacal.EACal(zh_t=True) for x in c.get_annual_solar_terms(y): if x[1] % 2 == 0: 前一节Time = 后一节Time 后一节Time = x[2].replace(tzinfo=None) 前一节Num = 后一节Num 后一节Num = x[1] if 前一节Time is not None and 后一节Time is not None: if 占时Time >= 前一节Time and 占时Time <= 后一节Time: break 气List = c.get_specified_solar_term(y, 前一节Num + 1) 气Time = 气List[2].replace(tzinfo=None) 气 = "{} {}".format(气List[0], datetime.datetime.strftime(气List[2], "%Y-%m-%d %H:%M:%S")) # 气 = "{} {}".format(气List[0], 气List[2].replace(tzinfo=None)) 节 = c.get_specified_solar_term(y, 前一节Num)[0] 节 = "{} {}".format(节, datetime.datetime.strftime(前一节Time, "%Y-%m-%d %H:%M:%S")) __年干支, __月干支, __日干支 = c.get_cycle_ymd(datetime.datetime(y, m, d)) 年柱 = 干支(干(__年干支[0]), 支(__年干支[1])) 月柱 = 干支(干(__月干支[0]), 支(__月干支[1])) 日柱 = 干支(干(__日干支[0]), 支(__日干支[1])) for i in ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]: if 月柱.支.六合(支(i)): 月将=支(i) break if 占时Time < 气Time: 月将=月将 + 1 时辰 = GetShiChen(h) if 日柱.干 == 干("甲") or 日柱.干 == 干("己"): 子时天干 = 干("甲") if 日柱.干 == 干("乙") or 日柱.干 == 干("庚"): 子时天干 = 干("丙") if 日柱.干 == 干("丙") or 日柱.干 == 干("辛"): 子时天干 = 干("戊") if 日柱.干 == 干("丁") or 日柱.干 == 干("壬"): 子时天干 = 干("庚") if 日柱.干 == 干("戊") or 日柱.干 == 干("癸"): 子时天干 = 干("壬") 时柱 = 干支(子时天干 + (时辰 - 支('子')), 时辰) if 时辰 == 支("子"): 日柱 = 日柱 + 1 return [年柱, 月柱, 日柱, 时柱, 月将, 节, 气]
def is阳遁(self): c = eacal.EACal(zh_s=True) __冬至Time = c.get_specified_solar_term(self.year, 21)[2].replace(tzinfo=None) __夏至Time = c.get_specified_solar_term(self.year, 9)[2].replace(tzinfo=None) __当日Time = datetime.datetime.strptime( "{0}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{4:02d}".format( self.year, self.month, self.day, self.hour, self.minute, self.sec), "%Y-%m-%d %H:%M:%S") if __当日Time >= __夏至Time and __当日Time < __冬至Time: return False return True
def do_天祸(sp): year = sp.year zhanRi = sp.占日 c = eacal.EACal(zh_s=True) liChun = c.get_specified_solar_term(year, 0)[2].replace(tzinfo=None) liXiao = c.get_specified_solar_term(year, 6)[2].replace(tzinfo=None) liQiu = c.get_specified_solar_term(year, 12)[2].replace(tzinfo=None) liDong = c.get_specified_solar_term(year, 18)[2].replace(tzinfo=None) t = None for i in [liChun, liXiao, liQiu, liDong]: t = GetLi(i.year, i.month, i.day, i.hour, i.minute, i.second)[2] if t == zhanRi: break if t is None: return yesterdayGan = zhanRi + (-1) yesterdayJiGong = shipan.寄宫(yesterdayGan.干) lin = sp.tp.临(shipan.寄宫(zhanRi.干)) if yesterdayJiGong == lin: sp.setGuaTi("天禍卦")
import eacal from ganzhiwuxin import * from shipan.shipan import ShiPan from common import GetLi y = 2018 # t = datetime.datetime.now() for k in range(0, 50): c = eacal.EACal(zh_s=True) year = y + k liChun = c.get_specified_solar_term(year, 0)[2].replace(tzinfo=None) liXiao = c.get_specified_solar_term(year, 6)[2].replace(tzinfo=None) liQiu = c.get_specified_solar_term(year, 12)[2].replace(tzinfo=None) liDong = c.get_specified_solar_term(year, 18)[2].replace(tzinfo=None) # t0 = t + datetime.timedelta(days=k) for j in [liChun, liXiao, liQiu, liDong]: __月将 = GetLi(j.year, j.month, j.day, j.hour, j.minute, j.second)[4] for i in range(0, 12): a = ShiPan(j.year, j.month, j.day, 20, 22, 7, str(__月将), str(支("子") + i), True, "abc", 0, 2018) if "天祸卦" in a.格局: print("{} {}".format(j, str(支("子") + i)))