周易算命源码|算命源码php|风水算命源码h5

  一个交互式的图形资源——以及对易经的解读——在其中你可以解码占卜的二进制,并仔细阅读学术解释。
  
  源码及演示:m.appwin.top

  周易算命源码|算命源码php|风水算命源码h5_第1张图片

  安裝套件
  

    pip install kintaiyi
    pip install --upgrade sxtwl, numpy, ephem, cn2an 

 
  起课方式

from kintaiyi import kintaiyi
    # 0 為年計;1 為月計;2 為日計:3 為時計
    #公元前
    Taiyi(-202,9,16,23,14).pan(1)
    {'太乙計': '月計', '公元日期': '-202年9月16日23時', '干支': ['戊戌', '辛酉', '庚戌', '丙子'], '農曆': {'年': -202, '月': 8, '日': 15}, '年號': '西漢高帝劉邦 高帝四年', '紀元': '第三紀第一甲子元', '時局': {'文': '陽遁十局', '數': 10}, '太乙': 4, '文昌': '丑', '太歲': '子', '合神': '丑', '計神': '寅', '始擊': '子', '定目': '子', '主算': [4, ['無天', '無地', '雜陽']], '客算': [11, ['無地', '陰中重陽']], '定算': [11, ['無地', '陰中重陽']], '九宮': {8: '大游', 3: '客參定參', 4: '主將太乙', 9: '', 5: '五風', 2: '主參八風', 7: '三風', 6: '', 1: '客將定將飛鳥小游'}, '十六宮': {'子': ['太歲', '始擊', '定目'], '丑': ['文昌', '合神', '四神'], '艮': [], '寅': [], '卯': [], '辰': ['君基'], '巽': ['五福'], '巳': ['民基'], '午': ['飛符', '太尊'], '未': ['臣基', '地乙'], '申': [], '坤': [], '酉': [], '戌': ['直符'], '乾': ['帝符'], '亥': ['天乙']}}
    #公元
    Taiyi(658,5,31,0,14).pan(0) 
    {'太乙計': '時計', '公元日期': '658年5月31日0時', '干支': ['戊午', '丁巳', '丙子', '戊子'], '農曆': {'年': 658, '月': 4, '日': 24}, '年號': '唐高宗李治 永徽九年', '紀元': '丙子元第二紀', '時局': '陽遁37局', '太乙': 6, '文昌': '坤', '太歲': '子', '合神': '丑', '計神': '寅', '始擊': '未', '定目': '未', '主算': [7, ['無天', '雜陰']], '客算': [8, ['無天', '雜陽']], '定算': [8, ['無天', '雜陽']], '九宮': {8: '客將定將大游', 3: '五風', 4: '客參定參', 9: '', 5: '', 2: '八風', 7: '主將三風', 6: '太乙', 1: '主參飛鳥小游'}, '十六宮': {'子': ['太歲', '太尊'], '丑': ['合神'], '艮': [], '寅': [], '卯': [], '辰': ['君基', '臣基', '帝符'], '巽': [], '巳': [], '午': [], '未': ['始擊', '定目'], '申': ['民基'], '坤': ['文昌'], '酉': [], '戌': [], '乾': ['五福'], '亥': []}}
    

  kintaiyi.py

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 27 18:11:44 2022
@author: kentang
"""

import re, itertools, time, pickle, os
import numpy as np
from math import pi
from sxtwl import fromSolar
from ephem import Sun, Date, Ecliptic, Equatorial, hour
from cn2an import an2cn

def jiazi():
    Gan, Zhi = '甲乙丙丁戊己庚辛壬癸','子丑寅卯辰巳午未申酉戌亥'
    return list(map(lambda x: "{}{}".format(Gan[x % len(Gan)],Zhi[x % len(Zhi)]), list(range(60))))

class Taiyi():
    def __init__(self, year, month, day, hour, minute):
        self.year, self.month, self.day, self.hour, self.minute = year, month, day, hour, minute
        self.taiyiyear  = 10153917
        self.jieqi = re.findall('..', '春分清明穀雨立夏小滿芒種夏至小暑大暑立秋處暑白露秋分寒露霜降立冬小雪大雪冬至小寒大寒立春雨水驚蟄')
        self.num =  [8,3,4,9,2,7,6,1]
        #干支
        self.Gan,self.Zhi = '甲乙丙丁戊己庚辛壬癸', '子丑寅卯辰巳午未申酉戌亥'
        #間辰
        self.jc = list("丑寅辰巳未申戌亥")
        self.jc1 = list("巽艮坤乾")
        self.tyjc = [1,3,7,9]
        #十六神
        self.sixteengod = dict(zip(re.findall("..", "地主陽德和德呂申高叢太陽大炅大神大威天道大武武德太簇陰主陰德大義"), "子丑艮寅卯辰巽巳午未坤申酉戌乾亥"))
        #陰陽遁定制
        self.gong = dict(zip(list("子丑艮寅卯辰巽巳午未坤申酉戌乾亥"), range(1,17)))
        self.gong1 = list("子丑艮寅卯辰巽巳午未坤申酉戌乾亥")
        #self.gong2 = dict(zip(list("亥子丑艮寅卯辰巽巳午未坤申酉戌乾"), [8,8,3,3,4,4,9,9,2,2,7,7,6,6,1,1]))
    #合神
    def jigod(self, ji):
        return dict(zip(list("子寅卯辰巳午丑亥戌酉申未"),list("丑亥戌酉申未子寅卯辰巳午"))).get(self.taishui(ji))
    #太歲
    def taishui(self, ji):
        gz =  self.gangzhi()
        return {0: gz[0][1], 1:gz[1][1], 2:gz[2][1], 3:gz[3][1]}.get(ji)

    def kingyear(self):
        def closest(lst, K): 
            return lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))] 
        data = pickle.load(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'history.pkl'), "rb")).split(",")
        y =  list(map(lambda x: int(x), data[0::7]))
        period = data[3::7]
        king = data[4::7]
        king_realname = data[5::7]
        preiodname = data[6::7]
        idx = y.index(closest(y, self.lunar_date_d().get("年")))
        year = year = self.lunar_date_d().get("年")
        if year < 1900:
            year = year - y[idx] +1
            pn = "{}{}年".format(preiodname[idx], an2cn(year))
            kn = "{}{}{}".format(period[idx], king[idx], king_realname[idx])
        if year > 1900 and year <1949:
            year = year - y[idx-1] +1
            pn = "{}{}年".format(preiodname[idx-1], an2cn(year))
            kn = "{}{}{}".format(period[idx-1], king[idx-1], king_realname[idx-1])
        if year > 1949:
            year = year - y[idx]
            pn = "{}{}年".format(preiodname[idx], an2cn(year))
            kn = "{}{}{}".format(period[idx], king[idx], king_realname[idx])
        return  "{} {}".format(kn, pn)
 
    def skyeyes_des(self, ji):
        yy = self.kook(ji).get("文")[0]
        k = self.kook(ji).get("數")
        dd = {"陽":",,辰迫,,,,,辰迫,囚,辰迫,囚,辰迫,,,勝,辰迫,囚,囚,客挾,,,,,,,,,,,,,,,,,,,客挾,囚,辰迫,客挾,客挾,囚,,宮迫,,主挾,宮迫,辰迫,,,,主挾,辰迫,宮迫,宮迫,,,,,客挾,,,,,,主挾,,,,,,,".split(","),
              "陰":",辰迫,,,,,,辰迫,囚,辰迫,囚,辰迫,,,,辰迫,囚,囚,,關客,,關客,,,宮迫,,,,,,,,,,,,辰迫,囚,,,,,囚,辰迫,宮迫,,宮迫,辰迫,,,,辰擊,宮迫,辰迫,,,,,,,,,,,,,客目掩,,,,,".split(",")}
        return dict(zip(range(1,73), dd.get(yy))).get(k)
    
    def skyeyes(self, ji):   
        skyeyes_dict = {
            "陽" : list("申酉戌乾乾亥子丑艮寅卯辰巽巳午未坤坤申酉戌乾乾亥子丑艮寅卯辰巽巳午未坤坤申酉戌乾乾亥子丑艮寅卯辰巽巳午未坤坤申酉戌乾乾亥子丑艮寅卯辰巽巳午未坤坤"),
            "陰" : list("寅卯辰巽巽巳午未坤申酉戌乾亥子丑艮艮寅卯辰巽巽巳午未坤申酉戌乾亥子丑艮艮寅卯辰巽巽巳午未坤申酉戌乾亥子丑艮艮寅卯辰巽巽巳午未坤申酉戌乾亥子丑艮艮")}
        return dict(zip(range(1,73),skyeyes_dict.get(self.kook(ji).get("文")[0]))).get(int(self.kook(ji).get("數")))
            
    #合神
    def hegod(self, ji):
        findji = {"陽":list("寅丑子亥戌酉申未午巳辰卯"), "陰":list("申未午巳辰卯寅丑子亥戌酉")}.get(self.kook(ji).get("文")[0])
        return dict(zip(self.Zhi, findji )).get(self.taishui(ji))

    def new_list(self, olist, o):
        a = olist.index(o)
        res1 = []
        for i in range(len(olist)):
            res1.append( olist[a % len(olist)])
            a = a + 1
        return res1
    
    def multi_key_dict_get(self, d, k):
        for keys, v in d.items():
            if k in keys:
                return v
        return None
    #干支
    def gangzhi(self):
        if self.hour == 23:
            d = Date(round((Date("{}/{}/{} {}:00:00.00".format(str(self.year).zfill(4), str(self.month).zfill(2), str(self.day).zfill(2), str(self.hour).zfill(2))) + 1 * hour), 3))
        else:
            d = Date("{}/{}/{} {}:00:00.00".format(str(self.year).zfill(4), str(self.month).zfill(2), str(self.day).zfill(2), str(self.hour).zfill(2) ))
        dd = list(d.tuple())
        cdate = fromSolar(dd[0], dd[1], dd[2])
        yTG,mTG,dTG,hTG = "{}{}".format(self.Gan[cdate.getYearGZ().tg], self.Zhi[cdate.getYearGZ().dz]), "{}{}".format(self.Gan[cdate.getMonthGZ().tg],self.Zhi[cdate.getMonthGZ().dz]), "{}{}".format(self.Gan[cdate.getDayGZ().tg], self.Zhi[cdate.getDayGZ().dz]), "{}{}".format(self.Gan[cdate.getHourGZ(dd[3]).tg], self.Zhi[cdate.getHourGZ(dd[3]).dz])
        return [yTG, mTG, dTG, hTG]
#%% #節氣
    def ecliptic_lon(self, jd_utc):
        return Ecliptic(Equatorial(Sun(jd_utc).ra,Sun(jd_utc).dec,epoch=jd_utc)).lon
    
    def sta(self, jd):
        return int(self.ecliptic_lon(jd)*180.0/pi/15)
    
    def iteration(self, jd):
        s1=self.sta(jd)
        s0=s1
        dt=1.0
        while True:
            jd+=dt
            s=self.sta(jd)
            if s0!=s:
                s0=s
                dt=-dt/2
            if abs(dt)<0.0000001 and s!=s1:
                break
        return jd
    
    def find_jq_date(self, year, month, day, hour, jq):
        jd=Date("{}/{}/{} {}:00:00.00".format(str(year).zfill(4), str(month).zfill(2), str(day).zfill(2), str(hour).zfill(2) ))
        e=self.ecliptic_lon(jd)
        n=int(e*180.0/pi/15)+1
        dzlist = []
        for i in range(24):
            if n>=24:
                n-=24
            jd=self.iteration(jd)
            d=Date(jd+1/3).tuple()
            b = {self.jieqi[n]: Date("{}/{}/{} {}:{}:00.00".format(str(d[0]).zfill(4), str(d[1]).zfill(2), str(d[2]).zfill(2), str(d[3]).zfill(2) , str(d[4]).zfill(2)))}
            n+=1
            dzlist.append(b)
        return list(dzlist[list(map(lambda i:list(i.keys())[0], dzlist)).index(jq)].values())[0]
    
    def lunar_date_d(self):
        day = fromSolar(self.year, self.month, self.day)
        return {"年":day.getLunarYear(),  "月": day.getLunarMonth(), "日":day.getLunarDay()}
    
    def xzdistance(self):
        return int(self.find_jq_date(self.year, self.month, self.day, self.hour, "夏至") -  Date("{}/{}/{} {}:00:00.00".format(str(self.year).zfill(4), str(self.month).zfill(2), str(self.day).zfill(2), str(self.hour).zfill(2))))
#%% 積年
    def accnum(self, ji):
        if ji == 0: #年計
            if self.year >= 0:
                return self.taiyiyear + self.year 
            elif self.year < 0:
                return self.taiyiyear + self.year + 1 
        elif ji == 1: #月計
            if self.year >= 0:
                accyear = self.taiyiyear + self.year - 1
            elif self.year < 0:
                accyear = self.taiyiyear + self.year + 1 
            return accyear * 12 + 2 + self.lunar_date_d().get("月")
        elif ji == 2:#日計
            return int(Date("{}/{}/{} {}:00:00.00".format(str(self.year).zfill(4), str(self.month).zfill(2), str(self.day).zfill(2), str(self.hour).zfill(2))) - Date("1900/06/19 00:00:00.00")) 
            #return (datetime.strptime("{0:04}-{1:02d}-{2:02d} 00:00:00".format(self.year, self.month, self.day), "%Y-%m-%d %H:%M:%S") - datetime.strptime("1900-06-19 00:00:00","%Y-%m-%d %H:%M:%S")).days
        elif ji == 3: #時計
            return int((Date("{}/{}/{} {}:00:00.00".format(str(self.year).zfill(4), str(self.month).zfill(2), str(self.day).zfill(2), str(self.hour).zfill(2))) - Date("1900/06/19 00:00:00.00") - 1)) * 12 + (self.hour + 1 ) // 2 + 1 
            #return ((datetime.strptime("{0:04}-{1:02d}-{2:02d} 00:00:00".format(self.year, self.month, self.day), "%Y-%m-%d %H:%M:%S") - datetime.strptime("1900-06-19 00:00:00","%Y-%m-%d %H:%M:%S")).days - 1 ) * 12 + (self.hour + 1 ) // 2 + 1
    
    def kook(self, ji):
        xz = self.xzdistance()
        current_date =  Date("{}/{}/{} {}:00:00.00".format(str(self.year).zfill(4), str(self.month).zfill(2), str(self.day).zfill(2), str(self.hour).zfill(2)))
        xz_date =  current_date - xz
        k = self.accnum(ji)%72
        if k == 0:
            k = 72
        if ji == 0 or ji == 1 or ji ==2:
            dun = "陽遁"
        elif ji == 3:
            if current_date >= xz_date and self.month >= 6:
                dun = "陰遁"
            else:
                dun = "陽遁"
        return {"文":"{}{}局".format(dun, an2cn(k)), "數":k}
    
    def getyuan(self, ji):
        accnum = self.accnum(ji)
        if round(accnum % 360) == 1:
            find_ji_num = 1
        else:
            find_ji_num = int(round((accnum % 360) / 72, 0))
        fiveyuen_d = dict(zip(range(1,6), jiazi()[0::12]))
        if find_ji_num == 0:
            find_ji_num = 1
        jiyuan = fiveyuen_d.get(find_ji_num) 
        return jiyuan
    
    def getepoch(self, ji):
        accnum = self.accnum(ji)
        if ji == 0 or ji == 1 or ji ==2:
            if round(accnum % 360) == 1:
                find_ji_num = 1
            else:
                find_ji_num = int((accnum % 360) / 60)
            if find_ji_num == 0:
                find_ji_num = 1
            find_ji_num2 = int(accnum % 360 % 72 % 24 / 3)
            cnum = list("一二三四五六七八九十")
            return {"元":dict(zip(range(1,8), cnum[0:7])).get(find_ji_num), "紀":dict(zip(range(1,8), cnum[0:7])).get(find_ji_num2)}
        elif ji == 3:
            epochdict = dict(zip([
                        ('甲子', '甲午', '乙丑', '乙未', '丙寅', '丙申', '丁卯', '丁酉', '戊辰', '戊戌'), 
                        ('己巳', '己亥', '庚午', '庚子', '辛未', '辛丑', '壬申', '壬寅', '癸酉', '癸卯'),
                        ('甲戌', '甲辰', '乙亥', '乙巳', '丙子', '丙午', '丁丑', '丁未', '戊寅', '戊申'),
                        ('己卯', '己酉', '庚辰', '庚戌', '辛巳', '辛亥', '壬午', '壬子', '癸未', '癸丑'),
                        ('甲申', '甲寅', '乙酉', '乙卯', '丙戌', '丙辰', '丁亥', '丁巳', '戊子', '戊午'),
                        ('己丑', '己未', '庚寅', '庚申', '辛卯', '辛酉', '壬辰', '壬戌', '癸巳', '癸亥')], 
                                 list("一二三四五六")))
            return "第{}紀".format(self.multi_key_dict_get(epochdict, self.gangzhi()[2]))
    
    def jiyuan(self, ji):
        if ji == 3:
            j = dict(zip([('甲子', '甲午', '乙丑', '乙未', '丙寅', '丙申', '丁卯', '丁酉', '戊辰', '戊戌', '己巳', '己亥'), 
                                  ('庚午', '庚子', '辛未', '辛丑', '壬申', '壬寅', '癸酉', '癸卯', '甲戌', '甲辰', '乙亥', '乙巳'),
                                  ('丙子', '丙午', '丁丑', '丁未', '戊寅', '戊申', '己卯', '己酉', '庚辰', '庚戌', '辛巳', '辛亥'),
                                  ('壬午', '壬子', '癸未', '癸丑', '甲申', '甲寅', '乙酉', '乙卯', '丙戌', '丙辰', '丁亥', '丁巳'),
                                  ('戊子', '戊午', '己丑', '己未', '庚寅', '庚申', '辛卯', '辛酉', '壬辰', '壬戌', '癸巳', '癸亥')], "甲子,丙子,戊子,庚子,壬子".split(",")))
            
            return "{}{}元".format(self.getepoch(ji), self.multi_key_dict_get(j, self.gangzhi()[2]))
        else:
            return "第{}紀第{}{}元".format(self.getepoch(ji).get("紀") ,self.getepoch(ji).get("元"), self.getyuan(ji))
    
    def ty(self, ji):
        arr = np.arange(10) 
        repetitions = 3
        arrangement = np.repeat(arr, repetitions) 
        arrangement_r = list(reversed(arrangement))
        yy_dict = {"陽": dict(zip(range(1,73), list(itertools.chain.from_iterable([list(arrangement)[3:15]+ list(arrangement)[18:]] * 3)))),  "陰": dict(zip(range(1,73), (list(arrangement_r)[:12] + list(arrangement_r)[15:][:-3]) * 3))}
        return yy_dict.get(self.kook(ji).get("文")[0]).get(self.kook(ji).get("數"))  
    
    #始擊
    def sf(self, ji):
        wc = self.skyeyes(ji)
        jd = self.jigod(ji)
        if wc == jd:
            sf = "艮"
            return sf
        elif wc != jd:
            start = self.new_list(self.gong1, jd)
            start1 = len(start[0:start.index("艮")+1])
            start2 = self.new_list(self.gong1, wc)[start1-1]
            return  start2
        
    #定目
    def se(self, ji):
        wc,hg,ts = self.skyeyes(ji),self.hegod(ji),self.taishui(ji)
        start = self.new_list(self.gong1, hg)
        start1 = len(start[:start.index(ts)+1])
        start2 = self.new_list(self.gong1, wc)[start1-1]
        return  start2

    def home_cal(self, ji):
        num = self.num
        lnum = [8, 8, 3,  3, 4,4, 9, 9, 2, 2, 7, 7, 6, 6, 1, 1]
        gong = list("亥子丑艮寅卯辰巽巳午未坤申酉戌乾")
        wc = self.skyeyes(ji)
        lg = dict(zip(gong, lnum))
        wc_num = lg.get(wc)
        ty = self.ty(ji)
        wc_jc = list(map(lambda x: x == wc, self.jc)).count(True)
        ty_jc = list(map(lambda x: x == ty, self.tyjc)).count(True)
        wc_jc1  = list(map(lambda x: x == wc, self.jc1)).count(True)
        wc_order = self.new_list(num, wc_num)
        if wc_jc == 1 and ty_jc != 1 and wc_jc1 !=1 :
            return sum(wc_order[: wc_order.index(ty)])+1
        elif wc_jc !=1 and ty_jc != 1 and wc_jc1 ==1:
            return sum(wc_order[: wc_order.index(ty)])
        elif wc_jc != 1 and ty_jc ==1 and wc_jc1 !=1:
            return sum(wc_order[: wc_order.index(ty)])
        elif wc_jc ==1 and ty_jc ==1 and wc_jc1 !=1 :
            return sum(wc_order[: wc_order.index(ty)])+1
        elif wc_jc !=1 and ty_jc ==1 and wc_jc1 ==1 :
            return sum(wc_order[: wc_order.index(ty)])
        elif wc_jc !=1 and ty_jc !=1 and wc_jc1 !=1 and ty != wc_num:
            return sum(wc_order[: wc_order.index(ty)])
        elif wc_jc !=1 and ty_jc !=1 and wc_jc1 !=1 and ty == wc_num:
            return ty
        
    def home_general(self, ji):
        home_g = self.home_cal(ji)  % 10
        if home_g == 0:
            home_g = 5
        return home_g
    
    def home_vgen(self, ji):
        home_vg = self.home_general(ji) *3 % 10
        if home_vg ==0:
            home_vg = 5
        return home_vg
        
    def away_cal(self, ji):
        num = self.num
        lnum = [8, 8, 3,  3, 4,4, 9, 9, 2, 2, 7, 7, 6, 6, 1, 1]
        gong = list("亥子丑艮寅卯辰巽巳午未坤申酉戌乾")
        sf = self.sf(ji)
        lg = dict(zip(gong, lnum))
        sf_num = lg.get(sf)
        ty = self.ty(ji)
        sf_jc = list(map(lambda x: x == sf, self.jc)).count(True)
        ty_jc = list(map(lambda x: x == ty, self.tyjc)).count(True)
        sf_jc1 = list(map(lambda x: x == sf, self.jc1)).count(True)
        sf_order = self.new_list(num, sf_num)
        if sf_jc == 1 and ty_jc != 1 and sf_jc1 !=1 :
            return sum(sf_order[: sf_order.index(ty)])+1
        elif sf_jc !=1 and ty_jc != 1 and sf_jc1 ==1:
            return sum(sf_order[: sf_order.index(ty)])
        elif sf_jc != 1 and ty_jc ==1 and sf_jc1 !=1:
            return sum(sf_order[: sf_order.index(ty)]) 
        elif sf_jc ==1 and ty_jc ==1 and sf_jc1 !=1 :
            return sum(sf_order[: sf_order.index(ty)])
        elif sf_jc !=1 and ty_jc ==1 and sf_jc1 ==1 :
            return sum(sf_order[: sf_order.index(ty)])
        elif sf_jc !=1 and ty_jc !=1 and sf_jc1 !=1 and sf_num != ty:
            return sum(sf_order[: sf_order.index(ty)])
        elif sf_jc !=1 and ty_jc !=1 and sf_jc1 !=1 and sf_num == ty:
            return ty
    
    def away_general(self, ji):
        away_g = self.away_cal(ji)  % 10
        if away_g == 0:
            away_g = 5
        return away_g
    
    def away_vgen(self, ji):
        away_vg = self.away_general(ji) *3 % 10
        if away_vg == 0:
            away_vg = 5
        return away_vg
        
    def set_cal(self, ji):
        num = self.num
        lnum = [8, 8, 3,  3, 4,4, 9, 9, 2, 2, 7, 7, 6, 6, 1, 1]
        gong = list("亥子丑艮寅卯辰巽巳午未坤申酉戌乾")
        se = self.se(ji)
        lg = dict(zip(gong, lnum))
        se_num = lg.get(se)
        ty = self.ty(ji)
        se_jc = list(map(lambda x: x == se, self.jc)).count(True)
        ty_jc = list(map(lambda x: x == ty, self.tyjc)).count(True)
        se_jc1 = list(map(lambda x: x == se, self.jc1)).count(True)
        se_order = self.new_list(num, se_num)
        if se_jc == 1 and ty_jc != 1 and se_jc1 !=1 :
            return sum(se_order[: se_order.index(ty)])+1
        elif se_jc !=1 and ty_jc != 1 and se_jc1 ==1:
            return sum(se_order[: se_order.index(ty)])
        elif se_jc != 1 and ty_jc ==1 and se_jc1 !=1:
            return sum(se_order[: se_order.index(ty)])
        elif se_jc ==1 and ty_jc ==1 and se_jc1 !=1 :
            return sum(se_order[: se_order.index(ty)])
        elif se_jc !=1 and ty_jc ==1 and se_jc1 ==1 :
            return sum(se_order[: se_order.index(ty)])
        elif se_jc !=1 and ty_jc !=1 and se_jc1 !=1 :
            return sum(se_order[: se_order.index(ty)])
        elif se_jc !=1 and ty_jc !=1 and se_jc1 !=1 and se_num != ty:
            return sum(se_order[: se_order.index(ty)])
        elif se_jc !=1 and ty_jc !=1 and se_jc1 !=1 and se_num == ty:
            return ty
    
    def cal_des(self, num):
        t = []
        if num > 10 and num % 10 > 5:
            t.append("三才足數")
        if num < 10:
            t.append("無天")
        if num % 10 < 5:
            t.append("無地")
        if num % 10 == 0:
            t.append("無人")
        numdict = {1: "雜陰", 2: "純陰", 3: "純陽", 4: "雜陽", 6: "純陰", 7: "雜陰",
                   8: "雜陽", 9: "純陽", 11: "陰中重陽", 12: "下和", 13: "雜重陽", 
                   14: "上和", 16: "下和", 17: "陰中重陽", 18: "上和", 19: "雜重陽",
                   22: "純陰", 23: "次和", 24: "雜重陰", 26: "純陰", 27: "下和", 
                   28: "雜重陰", 29: "次和", 31: "雜重陽", 32: "次和", 33: "純陽", 
                   34: "下和", 37: "雜重陽", 38: "下和", 39: "純陽"}
        t.append(numdict.get(num, None))
        return [i for i in t if i is not None]
    
    def set_general(self, ji):
        set_g = self.set_cal(ji)  % 10
        if set_g == 0:
            set_g = 5
        return set_g
    
    def set_vgen(self, ji):
        set_vg =  self.set_general(ji) *3 % 10
        if set_vg == 0:
            set_vg = 5
        return set_vg
    
    def sixteen_gong1(self, ji):
        dict1 = [{self.skyeyes(ji):"昌"},{self.hegod(ji):"合"},{self.sf(ji):"始"},
                {self.se(ji):"目"}, {self.kingbase(ji):"君"}, {self.officerbase(ji):"臣"}, {self.pplbase(ji):"民"},
                {self.fgd(ji):"四"},{self.skyyi(ji):"乙"},{self.earthyi(ji):"地"},{self.zhifu(ji):"符"},
                {self.flyfu(ji):"飛"},{self.kingfu(ji):"帝"}, {self.wufu(ji):"福"},  {self.jigod(ji):"計"}]
        res = {"子":"", "丑":"", "艮":"","寅":"", "卯":"", "辰":"", "巽":"","巳":"", "午":"", "未":"", "申":"", "坤":"", "酉":"", "戌":"", "乾":"", "亥":"", "中":""}
        for dict in dict1:
           for list in dict:
               if list in res:
                   try:
                       res[list] += (dict[list])
                   except TypeError:
                       pass
               else:
                   try:
                       res[list] = dict[list]
                   except TypeError:
                       pass
        rres = str(res.values())[11:].replace("([","").replace("'","").replace("])","").replace(" ", "").split(",")
        rrres = [re.findall("..", i) for i in rres]
        r = str(res.keys())[11:].replace("([","").replace("'","").replace("])","").replace(" ", "").split(",")
        return {r[i]:rrres[i] for i in range(0,16)}
    
    def sixteen_gong(self, ji):
        dict1 = [{self.skyeyes(ji):"文昌"},{self.taishui(ji):"太歲"},{self.hegod(ji):"合神"},{self.sf(ji):"始擊"},
                 {self.se(ji):"定目"}, {self.kingbase(ji):"君基"}, {self.officerbase(ji):"臣基"}, {self.pplbase(ji):"民基"},
                 {self.fgd(ji):"四神"},{self.skyyi(ji):"天乙"},{self.earthyi(ji):"地乙"},{self.zhifu(ji):"直符"},
                 {self.flyfu(ji):"飛符"},{self.kingfu(ji):"帝符"},{self.taijun(ji):"太尊"}, {self.wufu(ji):"五福"} ]
        res = {"子":"", "丑":"", "艮":"","寅":"", "卯":"", "辰":"", "巽":"","巳":"", "午":"", "未":"", "申":"", "坤":"", "酉":"", "戌":"", "乾":"", "亥":"", "中":""}
        for dict in dict1:
            for list in dict:
                if list in res:
                    try:
                        res[list] += (dict[list])
                    except TypeError:
                        pass
                else:
                    try:
                        res[list] = dict[list]
                    except TypeError:
                        pass
        rres = str(res.values())[11:].replace("([","").replace("'","").replace("])","").replace(" ", "").split(",")
        rrres = [re.findall("..", i) for i in rres]
        r = str(res.keys())[11:].replace("([","").replace("'","").replace("])","").replace(" ", "").split(",")
        return {r[i]:rrres[i] for i in range(0,16)}
    #九宮
    def nine_gong(self, ji):
        dict1 = [{self.home_general(ji):"主將"},{self.home_vgen(ji):"主參"},{self.away_general(ji):"客將"},
                 {self.away_vgen(ji):"客參"},{self.set_general(ji):"定將"},{self.set_vgen(ji):"定參"},
                 {self.ty(ji):"太乙"}, {self.threewind(ji):"三風"},  {self.fivewind(ji):"五風"},
                 {self.eightwind(ji):"八風"},  {self.flybird(ji):"飛鳥"},{self.bigyo(ji):"大游"},
                 {self.smyo(ji):"小游"},]
        res = {8:"", 3:"", 4:"", 9:"",5:"", 2:"", 7:"", 6:"", 1:""}
        for dict in dict1:
            for list in dict:
                if list in res:
                    try:
                        res[list] += (dict[list])
                    except TypeError:
                        pass
                else:
                    try:
                        res[list] = dict[list]
                    except TypeError:
                        pass
        return res 
    
    #君基
    def kingbase(self, ji):
        kb = (self.accnum(ji) +250) % 360  / 30
        kb_v = dict(zip(range(1,13), self.new_list(self.Zhi, "午"))).get(int(kb))
        if kb_v == 0 or kb_v ==None:
            kb_v = "中"
        return kb_v
    
    #臣基
    def officerbase(self, ji):
        ob = (self.accnum(ji)  +250) % 360  % 36 / 3
        ob_v =  dict(zip(range(1,13), self.new_list(self.Zhi, "午"))).get(int(ob))
        if ob_v == 0 or ob_v ==None:
            ob_v = "中"
        return ob_v
    #民基
    def pplbase(self, ji):
        pb = (self.accnum(ji)  +250) % 360 % 12
        pb_v = dict(zip(range(1,13), self.new_list(self.Zhi, "戌"))).get(int(pb))
        if pb_v == 0 or pb_v ==None:
            pb_v = "中"
        return  pb_v
    #大游
    def bigyo(self, ji):
        by = int((self.accnum(ji) +34) % 388)
        if by < 36:
            by = by
        elif by > 36:
            by = by / 36
        byv = dict(zip([7,8,9,1,2,3,4,6],range(1,9))).get(int(by))
        if byv == 0 or byv ==None:
            byv = 5
        return byv
    #小游
    def smyo(self, ji):
        sy = int(self.accnum(ji)  % 360)
        if sy < 24:
            sy = sy % 3 
        elif sy > 24:
            sy = sy % 24
            if sy > 3:
                sy = sy % 3
        syv = dict(zip([1,2,3,4,6,7,8,9],range(1,9))).get(int(sy))
        if syv == 0 or syv == None:
            syv = 5
        return syv
    #四神
    def fgd(self, ji):
        f = self.accnum(ji)  % 360 % 36 / 3 
        fv = dict(zip(range(1,13), self.new_list(self.Zhi, "亥"))).get(int(f))
        if fv == 0 or fv == None:
            fv = "中"
        return fv
    #天乙
    def skyyi(self, ji):
        f = self.accnum(ji)  % 360 % 36 / 3 
        fv = dict(zip(range(1,13), self.new_list(self.Zhi, "酉"))).get(int(f))
        if fv == 0 or fv == None:
            fv = "中"
        return fv
    #地乙
    def earthyi(self, ji):
        f = self.accnum(ji)  % 360 % 36 / 3
        fv = dict(zip(range(1,13), self.new_list(self.Zhi, "巳"))).get(int(f))
        if fv == 0 or fv == None:
            fv = "中"
        return fv
    #直符
    def zhifu(self, ji):
        f = self.accnum(ji)  % 360 % 36 / 3
        fv = dict(zip(range(1,14), ["中"]+self.new_list(self.Zhi, "酉"))).get(int(f))
        if fv == 0 or fv == None:
            fv = "中"
        return fv
    #飛符
    def flyfu(self, ji):
        f = self.accnum(ji) % 360 % 36 / 3
        fv = dict(zip(range(1,13), self.new_list(self.Zhi, "辰"))).get(int(f))
        if fv == 0 or fv == None:
            fv = "中"
        return fv
    #帝符
    def kingfu(self, ji):
        f = self.accnum(ji)  %20
        if f > 16:
            f = f - 16
        fv = dict(zip(range(1,17), self.new_list(self.gong1, "戌"))).get(int(f))
        if fv == 0 or fv== None:
            fv = "中"
        return fv
    #太尊
    def taijun(self, ji):
        f = self.accnum(ji)   % 4
        fv = dict(zip(range(1,5), list("子午卯酉"))).get(int(f))
        if fv == 0  or fv == None:
            fv = "中"
        return fv
    #飛鳥
    def flybird(self, ji):
        f = self.accnum(ji)   % 9
        fv = dict(zip(range(1,10), [1,8,3,4,9,2,7,6])).get(int(f))
        if fv == 0 or fv ==None:
            fv = 5
        return fv
    #五行
    def wuxing(self, ji):
        f = self.accnum(ji) // 5
        f = f % 5
        fv =  dict(zip(range(1,10), [1,3,5,7,9,2,4,6,8])).get(int(f))
        if fv == 0 or fv ==None:
            fv = 5
        return fv
    #三風
    def threewind(self, ji):
        f = self.accnum(ji)  % 9
        fv = dict(zip(range(1,9), [7,2,6,1,5,9,4,8])).get(int(f))
        if fv == 0 or fv == None:
            fv = 5
        return fv
    #五風
    def fivewind(self, ji):
        f = self.accnum(ji)  % 29
        if f > 10:
            f = f - 9
        fv = dict(zip(range(1,10), [1,3,5,7,9,2,4,6,8])).get(int(f))
        if fv == 0 or fv == None:
            fv = 5
        return fv
    #八風
    def eightwind(self, ji):
        f = self.accnum(ji)  % 9
        fv = dict(zip(range(1,9), [2,3,5,6,7,8,9,1])).get(int(f))
        if fv == 0 or fv == None:
            fv = 5
        return fv
    #五福
    def wufu(self, ji):
        f = int(self.accnum(ji)  + 250) % 225 / 45 
        fv = dict(zip(range(1,6), list("乾艮巽坤中"))).get(int(f))
        if fv == 0 or fv ==None:
            fv = 5
        return fv
    #八門
    def eight_door(self, ji):
        acc = self.accnum(ji) % 120
        if acc == 0:
            acc = 120
        eightdoor_zhishi = acc // 30
        if eightdoor_zhishi % 30 != 0:
           eightdoor_zhishi = eightdoor_zhishi + 1
        if self.kook()[0] == "陽":
            fdoor = [1,8,3,6]
        elif self.kook()[0] == "陰":
            fdoor = [9,2,7,4]
        #ty_gong = self.ty()
        return self.new_list(self.num, fdoor[eightdoor_zhishi]), eightdoor_zhishi
    
    def pan(self, ji):
        return {
                "太乙計":{0:"年計", 1:"月計", 2:"日計", 3:"時計"}.get(ji), 
                "公元日期":"{}年{}月{}日{}時".format(self.year, self.month, self.day, self.hour),
                "干支":self.gangzhi(),
                "農曆":self.lunar_date_d(),
                "年號":self.kingyear(),
                "紀元":self.jiyuan(ji),
                "局式":self.kook(ji),
                "太乙":self.ty(ji),
                "文昌":[self.skyeyes(ji), self.skyeyes_des(ji)],
                "太歲":self.taishui(ji),
                "合神":self.hegod(ji),
                "計神":self.jigod(ji),
                "始擊":self.sf(ji),
                "定目":self.se(ji),
                "主算":[self.home_cal(ji), self.cal_des(self.home_cal(ji))],
                "客算":[self.away_cal(ji), self.cal_des(self.away_cal(ji))],
                "定算":[self.set_cal(ji), self.cal_des(self.set_cal(ji))],
                "九宮":self.nine_gong(ji), 
                "十六宮":self.sixteen_gong(ji),
                }
    
    def html(self, ji):
        text = '''

'''+str(self.year)+"年"+str(self.month)+"月"+str(self.day)+"日"+str(self.hour)+"時"+'''
干支: '''+self.gangzhi()[0]+" "+self.gangzhi()[1]+" "+self.gangzhi()[2]+" "+self.gangzhi()[3]+''' 

'''+self.kingyear()+'''

'''+self.jiyuan(ji)+" "+self.kook(ji).get("文")+'''
主算:'''+str(self.home_cal(ji))+"".join(self.cal_des(self.home_cal(ji)))+'''
客算:'''+str(self.away_cal(ji))+"".join(self.cal_des(self.away_cal(ji)))+'''
定算:'''+str(self.set_cal(ji))+"".join(self.cal_des(self.set_cal(ji)))+'''

'''+"".join(['''''' for i in self.pan(ji).get("十六宮").get("巽")])+'''
'''+i+'''
'''+"".join(['''''' for i in self.pan(ji).get("十六宮").get("巳")])+'''
'''+i+'''
'''+"".join(['''''' for i in self.pan(ji).get("十六宮").get("午")])+'''
'''+i+'''
未  '''+"".join(['''''' for i in self.pan(ji).get("十六宮").get("未")])+'''
'''+i+'''
'''+"".join(['''''' for i in self.pan(ji).get("十六宮").get("坤")])+'''
'''+i+'''
'''+"".join(['''''' for i in self.pan(ji).get("十六宮").get("辰")])+'''
'''+i+'''
  '''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("申"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("卯"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("酉"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("寅"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("戌"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("艮"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("丑"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("子"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("亥"))))+'''
'''+i+'''
'''+"".join(list(map(lambda i:'''''', self.pan(ji).get("十六宮").get("乾"))))+'''
'''+i+'''

 

''' return text if __name__ == '__main__': tic = time.perf_counter() print(Taiyi(2022,9,22,0,0).pan(3) ) toc = time.perf_counter() print(f"{toc - tic:0.4f} seconds")

你可能感兴趣的:(html5)