22285461@qq.com 6 сар өмнө
parent
commit
3b013830f1
10 өөрчлөгдсөн 672 нэмэгдсэн , 925 устгасан
  1. 0 37
      Common.py
  2. 19 19
      ContentLogic.py
  3. 206 0
      DBTools.py
  4. 0 83
      GaoNengLogic.py
  5. 285 282
      ShenShaLogic.py
  6. 2 3
      SimpleLuckyDay.py
  7. 112 104
      logic.py
  8. 44 46
      main.py
  9. 0 348
      model.py
  10. 4 3
      yixue.py

+ 0 - 37
Common.py

@@ -2,7 +2,6 @@ import inspect
 
 import Configs
 from Configs import config_wuxing, config_canggan
-from model import Tiangan, Dizhi, Shishen, GaonengMid
 
 tiangan_ary = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
 dizhi_ary = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
@@ -167,35 +166,6 @@ def get_tiangan_by_dizhi(dizhi: str):
     return None
 
 
-# 查询和日元形成指定食神关系的天干地支
-def find_tiangan_dizhi_by_shishenguanxi(riyuan: str, jiancheng: str):
-    result = []
-    dts = Shishen.select().where(Shishen.wo == riyuan, Shishen.jiancheng == jiancheng)
-    if len(dts) > 0:
-        result.append(dts[0].ta)
-        dzs = Dizhi.select().where(Dizhi.gan1 == dts[0].ta)
-        for dz in dzs:
-            result.append(dz.name)
-    return result
-
-
-# 根据指定的arg1,指定的关系,指定的类别,查找符合条件的高能关系
-def find_gaoneng_by_arg_guanxi_leibie(arg: str, guanxi: str, leibie: str):
-    dts = GaonengMid.select().where(GaonengMid.arg1 == arg, GaonengMid.guanxi == guanxi,
-                                    GaonengMid.leibie == leibie)
-    if len(dts) > 0:
-        return dts
-    return []
-
-
-def get_lushen(riyuan: str):
-    result = None
-    dts = Tiangan.select().where(Tiangan.name == riyuan)
-    if len(dts) > 0:
-        result = dts[0].lushen
-    return result
-
-
 def is_lushen(text: str, riyuan: str):
     result = False
     if text in dizhi_ary:
@@ -227,13 +197,6 @@ def is_tiangan(text: str):
     return text in tiangan_ary
 
 
-# 用来查询简单的,只有2个参数的高能关系
-def queryGaoNengGuanXi(arg1: str, arg2: str, arg3: str, guanxi: str):
-    dt = GaonengMid.select().where(GaonengMid.arg1 == arg1, GaonengMid.arg2 == arg2, GaonengMid.arg3 == arg3,
-                                   GaonengMid.guanxi == guanxi).first()
-    return dt
-
-
 # 传入总共多少个藏干,以及当前藏干的index
 def calcCangGanPower(cangGanAmount: int, cangGanIndex: int, isMuKu: bool):
     power = 0

+ 19 - 19
ContentLogic.py

@@ -1,12 +1,12 @@
 import Common
-from LocalModel import BaZi, SiZhuWeiZhi, LiuZhu, ContentGaoNeng, ContentInfo
-from model import Wannianli, GaonengMid, ShishenJiedu, LuckyDay
+from DBTools import DBWanNianLi, DBShiShenJieDu, DBGaoNeng
+from LocalModel import SiZhuWeiZhi, LiuZhu, ContentGaoNeng, ContentInfo
 
 
-def createContent(bazi: BaZi):
+def createContent():
     return
     year = 2024
-    month = 5
+    month = 6
     maxDay = Common.get_max_day(year, month)
     total = []
     for day in range(1, maxDay + 1):
@@ -15,13 +15,15 @@ def createContent(bazi: BaZi):
             # print(info.riyuan, info.text, info.fromCangGan, info.fromGongHe, info.fromXing)
             total.append(info.to_db_data())
     print("calc content over")
-    LuckyDay.insert_many(total).execute()
+    # 操作前把luck day 这个表格清空
+    DBLuckDay.delete_by()
+    DBLuckDay.insert_all(total)
     print("save content over")
 
 
 def __create_contents_by_date(year: int, month: int, day: int):
     infoList: [ContentInfo] = []
-    dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).first()
+    dt = DBWanNianLi.query_first_by(nian=year, yue=month, ri=day)
     if dt is not None:
         for riyuan in Common.tiangan_ary:
             # print(month, day, riyuan)
@@ -50,8 +52,7 @@ def __calc_gonghe_data(lst: [ContentGaoNeng], tgZhus: [LiuZhu], riyuan: str):
         if item.guanxi == "拱合":
             tg = Common.get_tiangan_by_dizhi(item.fangxiang)
             for zhu in tgZhus:
-                dt = GaonengMid.select().where(GaonengMid.arg1 == tg, GaonengMid.arg2 == zhu.text,
-                                               GaonengMid.arg3 == None).first()
+                dt = DBGaoNeng.query_first_by(arg1=tg, arg2=zhu.text, arg3=None)
                 if dt is not None:
                     gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
                     gn.fromGongHe = True
@@ -75,8 +76,7 @@ def __calc_xing_data(lst: [ContentGaoNeng], tgZhus: [LiuZhu], riyuan: str):
             elif item.text == "丑戌刑":
                 chong1 = "丁"
                 chong2 = "癸"
-            dt = GaonengMid.select().where(GaonengMid.arg1 == chong1, GaonengMid.arg2 == chong2,
-                                           GaonengMid.guanxi == "冲").first()
+            dt = DBGaoNeng.query_first_by(arg1=chong1, arg2=chong2, guanxi="冲")
             if dt is not None:
                 gn = __build_content_gaoneng(dt, riyuan, -1, -1, None)
                 gn.fromXing = True
@@ -152,9 +152,10 @@ def __fill_jiedu(info: ContentInfo):
         guanxi = info.guanxi
         if guanxi == "暗合":
             guanxi = "合"
-        jd = ShishenJiedu.select().where(ShishenJiedu.arg1 == info.shishen1,
-                                         ShishenJiedu.arg2 == info.shishen2,
-                                         ShishenJiedu.guanxi == guanxi).first()
+        jd = DBShiShenJieDu.query_first_by(arg1=info.shishen1, arg2=info.shishen2, guanxi=guanxi)
+        # jd = ShishenJiedu.select().where(ShishenJiedu.arg1 == info.shishen1,
+        #                                  ShishenJiedu.arg2 == info.shishen2,
+        #                                  ShishenJiedu.guanxi == guanxi).first()
         if jd is not None:
             info.jiedu1 = jd.tip1
             info.jiedu2 = jd.tip2
@@ -230,7 +231,7 @@ def __build_zhu(text: str, weizhi: int, riyuan: str):
 
 def __calc_tiangan_gaonengs(key: str, zhus: [LiuZhu], riyuan: str, lst: [ContentGaoNeng]):
     for zhu in zhus:
-        dts = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu.text)
+        dts = DBGaoNeng.query_by(arg1=key, arg2=zhu.text)
         if len(dts) > 0:
             for dt in dts:
                 gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
@@ -242,15 +243,14 @@ def __calc_dizhi_gaonengs(key: str, zhus: [LiuZhu], riyuan: str, lst: [ContentGa
         for zhu3 in zhus:
             if zhu2.weizhi == zhu3.weizhi:
                 continue
-            dts = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu2.text,
-                                            GaonengMid.arg3 == zhu3.text)
+            dts = DBGaoNeng.query_by(arg1=key, arg2=zhu2.text, arg3=zhu3.text)
             if len(dts) > 0:
                 for dt in dts:
                     gn = __build_content_gaoneng(dt, riyuan, -1, zhu2.weizhi, zhu3.weizhi)
                     lst.append(gn)
 
     for zhu in zhus:
-        dts = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu.text, GaonengMid.arg3 == None)
+        dts = DBGaoNeng.query_by(arg1=key, arg2=zhu.text, arg3=None)
         if len(dts) > 0:
             for dt in dts:
                 gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
@@ -263,7 +263,7 @@ def __calc_canggan_gaonengs(riyuan: str, zhus: [LiuZhu], lst: [ContentGaoNeng]):
         for gan in gans:
             if gan is None:
                 continue
-            dts = GaonengMid.select().where(GaonengMid.arg1 == riyuan, GaonengMid.arg2 == gan)
+            dts = DBGaoNeng.query_by(arg1=riyuan, arg2=gan)
             if len(dts) > 0:
                 for dt in dts:
                     gn = __build_content_gaoneng(dt, riyuan, SiZhuWeiZhi.rigan.value, zhu.weizhi, None)
@@ -271,7 +271,7 @@ def __calc_canggan_gaonengs(riyuan: str, zhus: [LiuZhu], lst: [ContentGaoNeng]):
                     lst.append(gn)
 
 
-def __build_content_gaoneng(dt: GaonengMid, riyuan: str, zhu1: int, zhu2: int, zhu3: int):
+def __build_content_gaoneng(dt: DBGaoNeng, riyuan: str, zhu1: int, zhu2: int, zhu3: int):
     gn = ContentGaoNeng()
     gn.text = dt.desc
     gn.arg1 = dt.arg1

+ 206 - 0
DBTools.py

@@ -0,0 +1,206 @@
+from typing import Any
+
+from sqlalchemy import create_engine, Column, Integer, String
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import sessionmaker
+
+# test.db.cxhy.cn
+# localhost
+engine = create_engine('mysql+pymysql://yixue:Lai123@test.db.cxhy.cn/yixue', pool_pre_ping=True)
+
+Base = declarative_base()
+
+
+class DBBase(Base):
+    __abstract__ = True
+
+    def __repr__(self):
+        result = self.__class__.__name__ + "("
+        for attr in self.__dict__:
+            if attr.startswith("_") or attr.startswith("__") or attr == "__tablename__":
+                continue
+            result += attr + "=" + str(getattr(self, attr)) + " "
+        result += ")"
+        return result
+
+    def to_json_object(self, **kwargs: Any):
+        obj = {}
+        for attr in self.__dict__:
+            if attr.startswith("_") or attr.startswith("__") or attr == "__tablename__":
+                continue
+            obj[attr] = getattr(self, attr)
+        for key, value in kwargs.items():
+            obj[key] = value
+        return obj
+
+    @classmethod
+    def new_session(cls):
+        Session = sessionmaker(bind=engine)
+        session = Session()
+        return session
+
+    @classmethod
+    def insert(cls, **kwargs: Any):
+        ss = cls.new_session()
+        obj = cls()
+        for key in kwargs.keys():
+            if hasattr(obj, key):
+                setattr(obj, key, kwargs[key])
+        ss.add(obj)
+        ss.commit()
+        ss.close()
+
+    @classmethod
+    def insert_all(cls, items: []):
+        ss = cls.new_session()
+        lst = []
+        for item in items:
+            obj = cls()
+            for key in item.keys():
+                if hasattr(obj, key):
+                    setattr(obj, key, item[key])
+            lst.append(obj)
+        ss.add_all(lst)
+        ss.commit()
+        ss.close()
+
+    @classmethod
+    def delete_by(cls, **kwargs: Any):
+        ss = cls.new_session()
+        data = ss.query(cls).filter_by(**kwargs).all()
+        for dt in data:
+            ss.delete(dt)
+        ss.commit()
+        ss.close()
+
+    @classmethod
+    def query_by(cls, **kwargs: Any):
+        ss = cls.new_session()
+        data = ss.query(cls).filter_by(**kwargs).all()
+        ss.close()
+        return data
+
+    @classmethod
+    def query_first_by(cls, **kwargs: Any):
+        ss = cls.new_session()
+        data = ss.query(cls).filter_by(**kwargs).first()
+        ss.close()
+        return data
+
+    # 也是查询,但是不关闭session,用于后续继续执行其他如update操作
+    @classmethod
+    def query_keep(cls, **kwargs: Any):
+        ss = cls.new_session()
+        data = ss.query(cls).filter_by(**kwargs).all()
+        return [data, ss]
+
+    @classmethod
+    def check_exist(cls, **kwargs: Any):
+        return cls.query_first_by(**kwargs) is not None
+
+
+class DBTaiYangPianYi(DBBase):
+    __tablename__ = 'taiyangpianyi'
+    id = Column(Integer, primary_key=True)
+    month = Column(Integer)
+    day = Column(Integer)
+    diff = Column(Integer)
+
+
+class DBUserInfo(DBBase):
+    __tablename__ = 'user_info'
+
+    id = Column(Integer, primary_key=True)
+    name = Column(String)
+    beizhu = Column(String)
+    man = Column(Integer)
+    leibie = Column(Integer)
+    year = Column(Integer)
+    month = Column(Integer)
+    day = Column(Integer)
+    hour = Column(Integer)
+    minute = Column(Integer)
+    sheng = Column(String)
+    shi = Column(String)
+    qu = Column(String)
+    niangan = Column(String)
+    nianzhi = Column(String)
+    yuegan = Column(String)
+    yuezhi = Column(String)
+    rigan = Column(String)
+    rizhi = Column(String)
+    shigan = Column(String)
+    shizhi = Column(String)
+    customer = Column(String)
+    joinTime = Column(String)
+    enabled = Column(Integer)
+
+
+class DBWanNianLi(DBBase):
+    __tablename__ = 'wannianli'
+    id = Column(Integer, primary_key=True)
+    nian = Column(Integer)
+    yue = Column(Integer)
+    ri = Column(Integer)
+    nian_gan = Column(String)
+    nian_zhi = Column(String)
+    yue_gan = Column(String)
+    yue_zhi = Column(String)
+    ri_gan = Column(String)
+    ri_zhi = Column(String)
+
+
+class DBShiShenJieDu(DBBase):
+    __tablename__ = 'shishen_jiedu'
+    id = Column(Integer, primary_key=True)
+    arg1 = Column(String)
+    arg2 = Column(String)
+    guanxi = Column(String)
+    tip1 = Column(String)
+    tip2 = Column(String)
+    tip3 = Column(String)
+    tip4 = Column(String)
+    tip5 = Column(String)
+
+
+class DBLuckDay(DBBase):
+    __tablename__ = 'luck_day'
+    id = Column(Integer, primary_key=True)
+    year = Column(Integer)
+    month = Column(Integer)
+    day = Column(Integer)
+    desc = Column(String)
+    jiedu1 = Column(String)
+    jiedu2 = Column(String)
+    jiedu3 = Column(String)
+    jiedu4 = Column(String)
+    jiedu5 = Column(String)
+    tip = Column(String)
+
+
+class DBGaoNeng(DBBase):
+    __tablename__ = 'gaoneng_mid'
+    id = Column(Integer, primary_key=True)
+    arg1 = Column(String)
+    arg2 = Column(String)
+    arg3 = Column(String)
+    wuxing1 = Column(String)
+    wuxing2 = Column(String)
+    wuxing3 = Column(String)
+    guanxi = Column(String)
+    desc = Column(String)
+    father = Column(String)
+    leibie = Column(String)
+    hehua = Column(String)
+    fangxiang = Column(String)
+    tip = Column(String)
+
+
+class DBCustomUser(DBBase):
+    __tablename__ = 'custom_user'
+    id = Column(Integer, primary_key=True)
+    user = Column(String)
+    psd = Column(String)
+    name = Column(String)
+    sexy = Column(Integer)
+    online = Column(Integer)

+ 0 - 83
GaoNengLogic.py

@@ -3,7 +3,6 @@ import PowerLogic
 import SiZhuLogic
 from DataCenter import DataCenter
 from LocalModel import BaZi, GaoNeng, SiZhu
-from model import GaonengMid
 
 gaoneng_tips = [
     "合多:喜社交,擅处理人际关系,喜与人为善,不喜争斗;",
@@ -318,88 +317,6 @@ def __has_father(gns: [GaoNeng], gn: GaoNeng):
     return result
 
 
-def __build_gaoneng_object_from_db(data: GaonengMid, bazi: BaZi, zhu1: int, zhu2: int, zhu3: int, save: bool):
-    gn = GaoNeng()
-    gn.arg1 = data.arg1
-    gn.arg2 = data.arg2
-    gn.arg3 = data.arg3
-    gn.guanxi = data.guanxi
-    gn.text = data.desc
-    gn.father = data.father
-    gn.leibie = data.leibie
-    gn.wuxing1 = data.wuxing1
-    gn.wuxing2 = data.wuxing2
-    gn.wuxing3 = data.wuxing3
-    gn.hehua = data.hehua
-    gn.shishen1 = Common.get_shishen(gn.arg1, bazi.riGan.text)
-    gn.shishen2 = Common.get_shishen(gn.arg2, bazi.riGan.text)
-    gn.shishen3 = Common.get_shishen(gn.arg3, bazi.riGan.text)
-    gn.power1 = bazi.getPowerOfShiShen(gn.shishen1)
-    gn.power2 = bazi.getPowerOfShiShen(gn.shishen2)
-    gn.power3 = bazi.getPowerOfShiShen(gn.shishen3)
-    gn.zhu1 = zhu1
-    gn.zhu2 = zhu2
-    gn.zhu3 = zhu3
-    gn.tip = data.tip
-    gn.fangxiang = data.fangxiang
-    gn.key = __calc_key_of_gaoneng_data(zhu1, zhu2, zhu3, gn.text)
-    if gn.guanxi == "合":
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.heList):
-                bazi.gaonengInfo.heList.append(gn)
-    elif gn.guanxi == "冲":
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chongList):
-                bazi.gaonengInfo.chongList.append(gn)
-    elif gn.guanxi == "破":
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.poList):
-                bazi.gaonengInfo.poList.append(gn)
-    elif gn.guanxi == "穿":
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chuanList):
-                bazi.gaonengInfo.chuanList.append(gn)
-    elif gn.guanxi == "半合":
-        gn.banheZengQiang = gn.fangxiang
-        gn.banheZengQiangWuXing = Common.get_wuxing(gn.banheZengQiang)
-        gn.banheZengQiangShiShen = Common.get_shishen(gn.banheZengQiang, bazi.riGan.text)
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.banHeList):
-                bazi.gaonengInfo.banHeList.append(gn)
-    elif gn.guanxi == "拱合":
-        gn.gongheZengQiang = gn.fangxiang
-        gn.gongheZengQiangWuXing = Common.get_wuxing(gn.gongheZengQiang)
-        gn.gongheZengQiangShiShen = Common.get_shishen(gn.gongheZengQiang, bazi.riGan.text)
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.gongHeList):
-                bazi.gaonengInfo.gongHeList.append(gn)
-    elif gn.guanxi == "暗合":
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.anHeList):
-                bazi.gaonengInfo.anHeList.append(gn)
-    elif gn.guanxi == "三会":
-        gn.sanhuiZengQiang = gn.fangxiang
-        gn.sanhuiQiangWuXing = Common.get_wuxing(gn.sanhuiZengQiang)
-        gn.sanhuiZengQiangShiShen = Common.get_shishen(gn.sanhuiZengQiang, bazi.riGan.text)
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.sanHuiList):
-                bazi.gaonengInfo.sanHuiList.append(gn)
-    elif gn.guanxi == "自刑":
-        gn.zixingZengQiang = gn.fangxiang
-        gn.zixingZengQiangWuXing = Common.get_wuxing(gn.zixingZengQiang)
-        gn.zixingZengQiangShiShen = Common.get_shishen(gn.zixingZengQiang, bazi.riGan.text)
-        if save:
-            if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.ziXingList):
-                bazi.gaonengInfo.ziXingList.append(gn)
-    elif gn.guanxi == "刑":
-        if save:
-            __fill_data_for_gaoneng_xing(gn, bazi)
-            if save:
-                if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.xingList) and gn.arg3 is None:
-                    bazi.gaonengInfo.xingList.append(gn)
-    return gn
-
-
 def __fill_data_for_gaoneng_xing(gn: GaoNeng, bazi: BaZi):
     found = False
     if gn.text == "寅巳刑":

+ 285 - 282
ShenShaLogic.py

@@ -1,6 +1,5 @@
 import Common
 from LocalModel import BaZi, SiZhuWeiZhi, SiZhu, ShenSha
-from model import Tianyiguiren, ShenshaTips, Zaisha, Shishenzhilu, Tiangan, Dashe, Yima, Zhangsheng, Huagai, Taohua
 
 
 def check_shenshas(bazi: BaZi):
@@ -65,331 +64,335 @@ def __fill_data_in_bazi(key: str, name: str, tip: str, bazi: BaZi):
 
 def __check_tianyiguiren(bazi: BaZi):
     key = "天乙贵人"
-    dts = Tianyiguiren.select().where(Tianyiguiren.niangan == bazi.nianGan.text)
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    if len(dts) > 0:
-        for dt in dts:
-            if bazi.nianZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.nianzhu
-                bazi.add_shensha(wz, key, tip)
-            if bazi.yueZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.yuezhu
-                bazi.add_shensha(wz, key, tip)
-            if bazi.riZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.rizhu
-                bazi.add_shensha(wz, key, tip)
-            if bazi.shiZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.shizhu
-                bazi.add_shensha(wz, key, tip)
-
-    dts2 = Tianyiguiren.select().where(Tianyiguiren.rigan == bazi.riGan.text)
-    if len(dts2) > 0:
-        for dt in dts2:
-            if bazi.nianZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.nianzhu
-                bazi.add_shensha(wz, key, tip)
-            if bazi.yueZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.yuezhu
-                bazi.add_shensha(wz, key, tip)
-            if bazi.riZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.rizhu
-                bazi.add_shensha(wz, key, tip)
-            if bazi.shiZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.shizhu
-                bazi.add_shensha(wz, key, tip)
+    # dts = Tianyiguiren.select().where(Tianyiguiren.niangan == bazi.nianGan.text)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # if len(dts) > 0:
+    #     for dt in dts:
+    #         if bazi.nianZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.nianzhu
+    #             bazi.add_shensha(wz, key, tip)
+    #         if bazi.yueZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.yuezhu
+    #             bazi.add_shensha(wz, key, tip)
+    #         if bazi.riZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.rizhu
+    #             bazi.add_shensha(wz, key, tip)
+    #         if bazi.shiZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.shizhu
+    #             bazi.add_shensha(wz, key, tip)
+    #
+    # dts2 = Tianyiguiren.select().where(Tianyiguiren.rigan == bazi.riGan.text)
+    # if len(dts2) > 0:
+    #     for dt in dts2:
+    #         if bazi.nianZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.nianzhu
+    #             bazi.add_shensha(wz, key, tip)
+    #         if bazi.yueZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.yuezhu
+    #             bazi.add_shensha(wz, key, tip)
+    #         if bazi.riZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.rizhu
+    #             bazi.add_shensha(wz, key, tip)
+    #         if bazi.shiZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.shizhu
+    #             bazi.add_shensha(wz, key, tip)
 
 
 def __check_zaisha(bazi: BaZi):
     key = "灾煞"
-    dts = Zaisha.select().where(Zaisha.nianzhi == bazi.nianZhi.text)
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    if len(dts) > 0:
-        for dt in dts:
-            if bazi.yueZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.yuezhu
-                dz = SiZhuWeiZhi.yuezhi
-                bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
-            if bazi.riZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.rizhu
-                dz = SiZhuWeiZhi.rizhi
-                bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
-            if bazi.shiZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.shizhu
-                dz = SiZhuWeiZhi.shizhi
-                bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
-    dts2 = Zaisha.select().where(Zaisha.rizhi == bazi.riZhi.text)
-    if len(dts2) > 0:
-        for dt in dts2:
-            wz = SiZhuWeiZhi.unknown
-            if bazi.nianZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.nianzhu
-                dz = SiZhuWeiZhi.nianzhi
-                bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
-            if bazi.yueZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.yuezhu
-                dz = SiZhuWeiZhi.yuezhi
-                bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
-            if bazi.shiZhi.text == dt.dizhi:
-                wz = SiZhuWeiZhi.shizhu
-                dz = SiZhuWeiZhi.shizhi
-                bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
+    # dts = Zaisha.select().where(Zaisha.nianzhi == bazi.nianZhi.text)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # if len(dts) > 0:
+    #     for dt in dts:
+    #         if bazi.yueZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.yuezhu
+    #             dz = SiZhuWeiZhi.yuezhi
+    #             bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
+    #         if bazi.riZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.rizhu
+    #             dz = SiZhuWeiZhi.rizhi
+    #             bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
+    #         if bazi.shiZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.shizhu
+    #             dz = SiZhuWeiZhi.shizhi
+    #             bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
+    # dts2 = Zaisha.select().where(Zaisha.rizhi == bazi.riZhi.text)
+    # if len(dts2) > 0:
+    #     for dt in dts2:
+    #         wz = SiZhuWeiZhi.unknown
+    #         if bazi.nianZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.nianzhu
+    #             dz = SiZhuWeiZhi.nianzhi
+    #             bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
+    #         if bazi.yueZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.yuezhu
+    #             dz = SiZhuWeiZhi.yuezhi
+    #             bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
+    #         if bazi.shiZhi.text == dt.dizhi:
+    #             wz = SiZhuWeiZhi.shizhu
+    #             dz = SiZhuWeiZhi.shizhi
+    #             bazi.add_shensha(wz, key, tip, __get_zaisha_effect(bazi, dz))
 
 
 def __check_wenchangxing(bazi: BaZi):
     key = "文昌星"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    if bazi.nianGan.shiShen == "食":
-        dts = Shishenzhilu.select().where(Shishenzhilu.tiangan == bazi.nianGan.text)
-        if len(dts) > 0:
-            if bazi.nianZhi.text == dts[0].dizhi:
-                bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-    if bazi.yueGan.shiShen == "食":
-        dts = Shishenzhilu.select().where(Shishenzhilu.tiangan == bazi.yueGan.text)
-        if len(dts) > 0:
-            if bazi.yueZhi.text == dts[0].dizhi:
-                bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-    if bazi.shiGan.shiShen == "食":
-        dts = Shishenzhilu.select().where(Shishenzhilu.tiangan == bazi.shiGan.text)
-        if len(dts) > 0:
-            if bazi.shiZhi.text == dts[0].dizhi:
-                bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # if bazi.nianGan.shiShen == "食":
+    #     dts = Shishenzhilu.select().where(Shishenzhilu.tiangan == bazi.nianGan.text)
+    #     if len(dts) > 0:
+    #         if bazi.nianZhi.text == dts[0].dizhi:
+    #             bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    # if bazi.yueGan.shiShen == "食":
+    #     dts = Shishenzhilu.select().where(Shishenzhilu.tiangan == bazi.yueGan.text)
+    #     if len(dts) > 0:
+    #         if bazi.yueZhi.text == dts[0].dizhi:
+    #             bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    # if bazi.shiGan.shiShen == "食":
+    #     dts = Shishenzhilu.select().where(Shishenzhilu.tiangan == bazi.shiGan.text)
+    #     if len(dts) > 0:
+    #         if bazi.shiZhi.text == dts[0].dizhi:
+    #             bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_lushen(bazi: BaZi):
     key = "禄神"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    dts1 = Tiangan.select().where(Tiangan.name == bazi.nianGan.text)
-    if len(dts1) > 0:
-        if bazi.nianZhi.text == dts1[0].linguan:
-            bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-    dts2 = Tiangan.select().where(Tiangan.name == bazi.yueGan.text)
-    if len(dts2) > 0:
-        if bazi.yueZhi.text == dts2[0].linguan:
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-    dts3 = Tiangan.select().where(Tiangan.name == bazi.riGan.text)
-    if len(dts3) > 0:
-        if bazi.riZhi.text == dts3[0].linguan:
-            bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-    dts4 = Tiangan.select().where(Tiangan.name == bazi.shiGan.text)
-    if len(dts4) > 0:
-        if bazi.shiZhi.text == dts4[0].linguan:
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # dts1 = Tiangan.select().where(Tiangan.name == bazi.nianGan.text)
+    # if len(dts1) > 0:
+    #     if bazi.nianZhi.text == dts1[0].linguan:
+    #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    # dts2 = Tiangan.select().where(Tiangan.name == bazi.yueGan.text)
+    # if len(dts2) > 0:
+    #     if bazi.yueZhi.text == dts2[0].linguan:
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    # dts3 = Tiangan.select().where(Tiangan.name == bazi.riGan.text)
+    # if len(dts3) > 0:
+    #     if bazi.riZhi.text == dts3[0].linguan:
+    #         bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    # dts4 = Tiangan.select().where(Tiangan.name == bazi.shiGan.text)
+    # if len(dts4) > 0:
+    #     if bazi.shiZhi.text == dts4[0].linguan:
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_kuigang(bazi: BaZi):
     key = "魁罡"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    if bazi.nianGan.text == "庚" and bazi.nianZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-    if bazi.nianGan.text == "庚" and bazi.nianZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-    if bazi.nianGan.text == "戊" and bazi.nianZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-    if bazi.nianGan.text == "壬" and bazi.nianZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-
-    if bazi.yueGan.text == "庚" and bazi.yueZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-    if bazi.yueGan.text == "庚" and bazi.yueZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-    if bazi.yueGan.text == "戊" and bazi.yueZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-    if bazi.yueGan.text == "壬" and bazi.yueZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-
-    if bazi.riGan.text == "庚" and bazi.riZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-    if bazi.riGan.text == "庚" and bazi.riZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-    if bazi.riGan.text == "戊" and bazi.riZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-    if bazi.riGan.text == "壬" and bazi.riZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-
-    if bazi.shiGan.text == "庚" and bazi.shiZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
-    if bazi.shiGan.text == "庚" and bazi.shiZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
-    if bazi.shiGan.text == "戊" and bazi.shiZhi.text == "戌":
-        bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
-    if bazi.shiGan.text == "壬" and bazi.shiZhi.text == "辰":
-        bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # if bazi.nianGan.text == "庚" and bazi.nianZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    # if bazi.nianGan.text == "庚" and bazi.nianZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    # if bazi.nianGan.text == "戊" and bazi.nianZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    # if bazi.nianGan.text == "壬" and bazi.nianZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #
+    # if bazi.yueGan.text == "庚" and bazi.yueZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    # if bazi.yueGan.text == "庚" and bazi.yueZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    # if bazi.yueGan.text == "戊" and bazi.yueZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    # if bazi.yueGan.text == "壬" and bazi.yueZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #
+    # if bazi.riGan.text == "庚" and bazi.riZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    # if bazi.riGan.text == "庚" and bazi.riZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    # if bazi.riGan.text == "戊" and bazi.riZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    # if bazi.riGan.text == "壬" and bazi.riZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    #
+    # if bazi.shiGan.text == "庚" and bazi.shiZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # if bazi.shiGan.text == "庚" and bazi.shiZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # if bazi.shiGan.text == "戊" and bazi.shiZhi.text == "戌":
+    #     bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # if bazi.shiGan.text == "壬" and bazi.shiZhi.text == "辰":
+    #     bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_dashe(bazi: BaZi):
     key = "大赦"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    dts = Dashe.select().where(Dashe.rigan == bazi.riGan.text)
-    if len(dts) > 0:
-        if bazi.nianGan.text == dts[0].tiangan and bazi.nianZhi.text == dts[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-        if bazi.yueGan.text == dts[0].tiangan and bazi.yueZhi.text == dts[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-        if bazi.shiGan.text == dts[0].tiangan and bazi.shiZhi.text == dts[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # dts = Dashe.select().where(Dashe.rigan == bazi.riGan.text)
+    # if len(dts) > 0:
+    #     if bazi.nianGan.text == dts[0].tiangan and bazi.nianZhi.text == dts[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #     if bazi.yueGan.text == dts[0].tiangan and bazi.yueZhi.text == dts[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     if bazi.shiGan.text == dts[0].tiangan and bazi.shiZhi.text == dts[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_yima(bazi: BaZi):
     key = "驿马"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    dts1 = Yima.select().where(Yima.dizhi == bazi.nianZhi.text)
-    if len(dts1) > 0:
-        if bazi.yueZhi.text == dts1[0].chong:
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-        if bazi.riZhi.text == dts1[0].chong:
-            bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-        if bazi.shiZhi.text == dts1[0].chong:
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
-    dts2 = Yima.select().where(Yima.dizhi == bazi.riZhi.text)
-    if len(dts2) > 0:
-        if bazi.nianZhi.text == dts2[0].chong:
-            bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-        if bazi.yueZhi.text == dts2[0].chong:
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-        if bazi.shiZhi.text == dts2[0].chong:
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # dts1 = Yima.select().where(Yima.dizhi == bazi.nianZhi.text)
+    # if len(dts1) > 0:
+    #     if bazi.yueZhi.text == dts1[0].chong:
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     if bazi.riZhi.text == dts1[0].chong:
+    #         bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    #     if bazi.shiZhi.text == dts1[0].chong:
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # dts2 = Yima.select().where(Yima.dizhi == bazi.riZhi.text)
+    # if len(dts2) > 0:
+    #     if bazi.nianZhi.text == dts2[0].chong:
+    #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #     if bazi.yueZhi.text == dts2[0].chong:
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     if bazi.shiZhi.text == dts2[0].chong:
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_jiangxing(bazi: BaZi):
     key = "将星"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    ary = ["子", "午", "卯", "酉"]
-    if ary.__contains__(bazi.nianZhi.text):
-        wz = SiZhuWeiZhi.nianzhu
-        dz = SiZhuWeiZhi.nianzhi
-        bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
-    if ary.__contains__(bazi.yueZhi.text):
-        wz = SiZhuWeiZhi.yuezhu
-        dz = SiZhuWeiZhi.yuezhi
-        bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
-    if ary.__contains__(bazi.riZhi.text):
-        wz = SiZhuWeiZhi.rizhu
-        dz = SiZhuWeiZhi.rizhi
-        bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
-    if ary.__contains__(bazi.shiZhi.text):
-        wz = SiZhuWeiZhi.shizhu
-        dz = SiZhuWeiZhi.shizhi
-        bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # ary = ["子", "午", "卯", "酉"]
+    # if ary.__contains__(bazi.nianZhi.text):
+    #     wz = SiZhuWeiZhi.nianzhu
+    #     dz = SiZhuWeiZhi.nianzhi
+    #     bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
+    # if ary.__contains__(bazi.yueZhi.text):
+    #     wz = SiZhuWeiZhi.yuezhu
+    #     dz = SiZhuWeiZhi.yuezhi
+    #     bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
+    # if ary.__contains__(bazi.riZhi.text):
+    #     wz = SiZhuWeiZhi.rizhu
+    #     dz = SiZhuWeiZhi.rizhi
+    #     bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
+    # if ary.__contains__(bazi.shiZhi.text):
+    #     wz = SiZhuWeiZhi.shizhu
+    #     dz = SiZhuWeiZhi.shizhi
+    #     bazi.add_shensha(wz, key, tip, __get_jiangxing_effect(bazi, dz))
 
 
 def __check_yangren(bazi: BaZi):
     key = "羊刃"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    if bazi.nianZhi.shiShen == "劫":
-        dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.nianZhi.text)
-        if len(dts) > 0:
-            if dts[0].zhangsheng == "帝":
-                bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-
-    if bazi.yueZhi.shiShen == "劫":
-        dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.yueZhi.text)
-        if len(dts) > 0:
-            if dts[0].zhangsheng == "帝":
-                bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-
-    if bazi.riZhi.shiShen == "劫":
-        dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.riZhi.text)
-        if len(dts) > 0:
-            if dts[0].zhangsheng == "帝":
-                bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-
-    if bazi.shiZhi.shiShen == "劫":
-        dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.shiZhi.text)
-        if len(dts) > 0:
-            if dts[0].zhangsheng == "帝":
-                bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # if bazi.nianZhi.shiShen == "劫":
+    #     # dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.nianZhi.text)
+    #     # if len(dts) > 0:
+    #     #     if dts[0].zhangsheng == "帝":
+    #     #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #     pass
+    #
+    # if bazi.yueZhi.shiShen == "劫":
+    #     # dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.yueZhi.text)
+    #     # if len(dts) > 0:
+    #     #     if dts[0].zhangsheng == "帝":
+    #     #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     pass
+    #
+    # if bazi.riZhi.shiShen == "劫":
+    #     # dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.riZhi.text)
+    #     # if len(dts) > 0:
+    #     #     if dts[0].zhangsheng == "帝":
+    #     #         bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    #     pass
+    #
+    # if bazi.shiZhi.shiShen == "劫":
+    #     # dts = Zhangsheng.select().where(Zhangsheng.tiangan == bazi.riGan.text, Zhangsheng.dizhi == bazi.shiZhi.text)
+    #     # if len(dts) > 0:
+    #     #     if dts[0].zhangsheng == "帝":
+    #     #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    #     pass
 
 
 def __check_diwang(bazi: BaZi):
     key = "地网"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    if bazi.nianZhi.text == "辰" or bazi.nianZhi.text == "戌":
-        if bazi.yueZhi.text == "巳" or bazi.yueZhi.text == "亥":
-            bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-        if bazi.riZhi.text == "巳" or bazi.riZhi.text == "亥":
-            bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-        if bazi.shiZhi.text == "巳" or bazi.shiZhi.text == "亥":
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
-    if bazi.riZhi.text == "辰" or bazi.riZhi.text == "戌":
-        if bazi.nianZhi.text == "巳" or bazi.nianZhi.text == "亥":
-            bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-        if bazi.yueZhi.text == "巳" or bazi.yueZhi.text == "亥":
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-        if bazi.shiZhi.text == "巳" or bazi.shiZhi.text == "亥":
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # if bazi.nianZhi.text == "辰" or bazi.nianZhi.text == "戌":
+    #     if bazi.yueZhi.text == "巳" or bazi.yueZhi.text == "亥":
+    #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #     if bazi.riZhi.text == "巳" or bazi.riZhi.text == "亥":
+    #         bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    #     if bazi.shiZhi.text == "巳" or bazi.shiZhi.text == "亥":
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # if bazi.riZhi.text == "辰" or bazi.riZhi.text == "戌":
+    #     if bazi.nianZhi.text == "巳" or bazi.nianZhi.text == "亥":
+    #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #     if bazi.yueZhi.text == "巳" or bazi.yueZhi.text == "亥":
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     if bazi.shiZhi.text == "巳" or bazi.shiZhi.text == "亥":
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_huagai(bazi: BaZi):
     key = "华盖"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    dt1 = Huagai.select().where(Huagai.nianzhi == bazi.nianZhi.text)
-    if len(dt1) > 0:
-        if bazi.yueZhi.text == dt1[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-        if bazi.riZhi.text == dt1[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
-        if bazi.shiZhi.text == dt1[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
-    dt2 = Huagai.select().where(Huagai.rizhi == bazi.riZhi.text)
-    if len(dt2) > 0:
-        if bazi.nianZhi.text == dt2[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
-        if bazi.yueZhi.text == dt2[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
-        if bazi.shiZhi.text == dt2[0].dizhi:
-            bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # dt1 = Huagai.select().where(Huagai.nianzhi == bazi.nianZhi.text)
+    # if len(dt1) > 0:
+    #     if bazi.yueZhi.text == dt1[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     if bazi.riZhi.text == dt1[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.rizhu, key, tip)
+    #     if bazi.shiZhi.text == dt1[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
+    # dt2 = Huagai.select().where(Huagai.rizhi == bazi.riZhi.text)
+    # if len(dt2) > 0:
+    #     if bazi.nianZhi.text == dt2[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.nianzhu, key, tip)
+    #     if bazi.yueZhi.text == dt2[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.yuezhu, key, tip)
+    #     if bazi.shiZhi.text == dt2[0].dizhi:
+    #         bazi.add_shensha(SiZhuWeiZhi.shizhu, key, tip)
 
 
 def __check_taohua(bazi: BaZi):
     key = "桃花"
-    tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
-    dts1 = Taohua.select().where(Taohua.nianzhi == bazi.nianZhi.text)
-    if len(dts1) > 0:
-        if bazi.yueZhi.text == dts1[0].dizhi:
-            wz = SiZhuWeiZhi.yuezhu
-            dz = SiZhuWeiZhi.yuezhi
-            zhu = bazi.yueZhi
-            gan = bazi.yueGan
-            zhuStr = "月柱"
-            bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
-        if bazi.riZhi.text == dts1[0].dizhi:
-            wz = SiZhuWeiZhi.rizhu
-            dz = SiZhuWeiZhi.rizhi
-            zhu = bazi.riZhi
-            gan = bazi.riGan
-            zhuStr = "日柱"
-            bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
-        if bazi.shiZhi.text == dts1[0].dizhi:
-            wz = SiZhuWeiZhi.shizhu
-            dz = SiZhuWeiZhi.shizhi
-            zhu = bazi.shiZhi
-            gan = bazi.shiGan
-            zhuStr = "时柱"
-            bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
-
-    dts2 = Taohua.select().where(Taohua.rizhi == bazi.riZhi.text)
-    if len(dts2) > 0:
-        if bazi.nianZhi.text == dts2[0].dizhi:
-            wz = SiZhuWeiZhi.nianzhu
-            dz = SiZhuWeiZhi.nianzhi
-            zhu = bazi.nianZhi
-            gan = bazi.nianGan
-            zhuStr = "年柱"
-            bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
-        if bazi.yueZhi.text == dts2[0].dizhi:
-            wz = SiZhuWeiZhi.yuezhu
-            dz = SiZhuWeiZhi.yuezhi
-            zhu = bazi.yueZhi
-            gan = bazi.yueGan
-            zhuStr = "月柱"
-            bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
-        if bazi.shiZhi.text == dts2[0].dizhi:
-            wz = SiZhuWeiZhi.shizhu
-            dz = SiZhuWeiZhi.shizhi
-            zhu = bazi.shiZhi
-            gan = bazi.shiGan
-            zhuStr = "时柱"
-            bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
+    # tip = ShenshaTips.select().where(ShenshaTips.shensha == key)[0].tips
+    # dts1 = Taohua.select().where(Taohua.nianzhi == bazi.nianZhi.text)
+    # if len(dts1) > 0:
+    #     if bazi.yueZhi.text == dts1[0].dizhi:
+    #         wz = SiZhuWeiZhi.yuezhu
+    #         dz = SiZhuWeiZhi.yuezhi
+    #         zhu = bazi.yueZhi
+    #         gan = bazi.yueGan
+    #         zhuStr = "月柱"
+    #         bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
+    #     if bazi.riZhi.text == dts1[0].dizhi:
+    #         wz = SiZhuWeiZhi.rizhu
+    #         dz = SiZhuWeiZhi.rizhi
+    #         zhu = bazi.riZhi
+    #         gan = bazi.riGan
+    #         zhuStr = "日柱"
+    #         bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
+    #     if bazi.shiZhi.text == dts1[0].dizhi:
+    #         wz = SiZhuWeiZhi.shizhu
+    #         dz = SiZhuWeiZhi.shizhi
+    #         zhu = bazi.shiZhi
+    #         gan = bazi.shiGan
+    #         zhuStr = "时柱"
+    #         bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
+    #
+    # dts2 = Taohua.select().where(Taohua.rizhi == bazi.riZhi.text)
+    # if len(dts2) > 0:
+    #     if bazi.nianZhi.text == dts2[0].dizhi:
+    #         wz = SiZhuWeiZhi.nianzhu
+    #         dz = SiZhuWeiZhi.nianzhi
+    #         zhu = bazi.nianZhi
+    #         gan = bazi.nianGan
+    #         zhuStr = "年柱"
+    #         bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
+    #     if bazi.yueZhi.text == dts2[0].dizhi:
+    #         wz = SiZhuWeiZhi.yuezhu
+    #         dz = SiZhuWeiZhi.yuezhi
+    #         zhu = bazi.yueZhi
+    #         gan = bazi.yueGan
+    #         zhuStr = "月柱"
+    #         bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
+    #     if bazi.shiZhi.text == dts2[0].dizhi:
+    #         wz = SiZhuWeiZhi.shizhu
+    #         dz = SiZhuWeiZhi.shizhi
+    #         zhu = bazi.shiZhi
+    #         gan = bazi.shiGan
+    #         zhuStr = "时柱"
+    #         bazi.add_shensha(wz, key, tip, __get_taohua_effect(bazi, zhu, gan, wz, dz, zhuStr))
 
 
 def __get_jiangxing_effect(bazi: BaZi, wz: SiZhuWeiZhi):

+ 2 - 3
SimpleLuckyDay.py

@@ -2,9 +2,9 @@ import datetime
 
 import GaoNengLogic
 import SiZhuLogic
+from DBTools import DBWanNianLi
 from DataCenter import DataCenter
 from LocalModel import BaZi, LuckyDayInfo, SiZhu, SiZhuWeiZhi
-from model import Wannianli
 
 
 def calc_simple_lucky_day(bazi: BaZi, dc: DataCenter):
@@ -13,8 +13,7 @@ def calc_simple_lucky_day(bazi: BaZi, dc: DataCenter):
     for i in range(0, 1):
         diff = datetime.timedelta(days=i)
         cur = dt + diff
-        dts = Wannianli.select().where(Wannianli.nian == cur.year, Wannianli.yue == cur.month,
-                                       Wannianli.ri == cur.day).first()
+        dts = DBWanNianLi.query_first_by(nian=cur.year, yue=cur.month, ri=cur.day)
 
         if dts is not None:
             # print(dts.nian_gan, dts.nian_zhi, "年 ", dts.yue_gan, dts.yue_zhi, "月 ", dts.ri_gan, dts.ri_zhi, "日")

+ 112 - 104
logic.py

@@ -1,41 +1,44 @@
-from model import Wannianli, WannianliJieqi
+from DBTools import DBWanNianLi
 from tools import *
 from yixue import *
 
 
 def get_last_day_info(year: int):
-    dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == 12, Wannianli.ri == 31)
-    data = dt[0]
-    if data.ri_gan == "":
-        return None
+    dt = DBWanNianLi.query_first_by(nian=year, yue=12, ri=31)
+    if dt is not None:
+        if dt.ri_gan == "":
+            return None
+        else:
+            return dt
     else:
-        return data
+        return None
 
 
 def _do_update_ri_by_year(year: int, start_rigan: str, start_rizhi: str):
-    last_rigan = start_rigan
-    last_rizhi = start_rizhi
-    for month in range(1, 13):
-        max_day = get_max_day(year, month)
-        print("处理", year, month, "月数据")
-        for day in range(1, max_day + 1):
-            if month == 1 and day == 1:
-                rigan = last_rigan
-                rizhi = last_rizhi
-            else:
-                rigan = next_tiangan(last_rigan)
-                rizhi = next_dizhi(last_rizhi)
-                last_rigan = rigan
-                last_rizhi = rizhi
-            Wannianli.update({
-                "ri_gan": rigan,
-                "ri_zhi": rizhi,
-            }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
-    print("update over last:", last_rigan, last_rizhi)
+    pass
+    # last_rigan = start_rigan
+    # last_rizhi = start_rizhi
+    # for month in range(1, 13):
+    #     max_day = get_max_day(year, month)
+    #     print("处理", year, month, "月数据")
+    #     for day in range(1, max_day + 1):
+    #         if month == 1 and day == 1:
+    #             rigan = last_rigan
+    #             rizhi = last_rizhi
+    #         else:
+    #             rigan = next_tiangan(last_rigan)
+    #             rizhi = next_dizhi(last_rizhi)
+    #             last_rigan = rigan
+    #             last_rizhi = rizhi
+    #         Wannianli.update({
+    #             "ri_gan": rigan,
+    #             "ri_zhi": rizhi,
+    #         }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
+    # print("update over last:", last_rigan, last_rizhi)
 
 
 def update_ri_by_year(year: int):
-    start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == 1, Wannianli.ri == 1)
+    start = DBWanNianLi.query_by(nian=year, yue=1, ri=1)
     start_data = start[0]
     if start_data.ri_gan == "":
         print(year, "1月1日未配置初始值,从上一年取得数据")
@@ -53,40 +56,42 @@ def update_ri_by_year(year: int):
 
 
 def get_wannianli_data(year: int, month: int, day: int):
-    dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day)
-    if len(dt) > 0:
-        return dt[0]
-    else:
-        print(year, month, day, "has empty data")
-        return None
+    return None
+    # dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day)
+    # if len(dt) > 0:
+    #     return dt[0]
+    # else:
+    #     print(year, month, day, "has empty data")
+    #     return None
 
 
-def get_jieqi_of_month(jieqi: WannianliJieqi, month: int):
-    ary = [jieqi.xiaohan, jieqi.lichun, jieqi.jingzhe, jieqi.qingming, jieqi.lixia,
-           jieqi.mangzhong, jieqi.xiaoshu, jieqi.liqiu, jieqi.bailu, jieqi.hanlu,
-           jieqi.lidong, jieqi.daxue]
-    return ary[month - 1]
+# def get_jieqi_of_month(jieqi: WannianliJieqi, month: int):
+#     ary = [jieqi.xiaohan, jieqi.lichun, jieqi.jingzhe, jieqi.qingming, jieqi.lixia,
+#            jieqi.mangzhong, jieqi.xiaoshu, jieqi.liqiu, jieqi.bailu, jieqi.hanlu,
+#            jieqi.lidong, jieqi.daxue]
+#     return ary[month - 1]
 
 
 def _do_update_yue_by_year(year: int, month: int, start_yuegan: str, start_yuezhi: str):
-    jieqi = WannianliJieqi.select().where(WannianliJieqi.nianfen == year)
-    jieqi_day = get_jieqi_of_month(jieqi[0], month)
-    print("处理", year, month, "月数据, 节气日期是:", jieqi_day)
-    key_day = str(jieqi_day).split(".")[1]
-    max_day = get_max_day(year, month)
-    for day in range(1, max_day + 1):
-        if day < int(key_day):
-            yuegan = start_yuegan
-            yuezhi = start_yuezhi
-        else:
-            yuegan = next_tiangan(start_yuegan)
-            yuezhi = next_dizhi(start_yuezhi)
-        # print(year, month, day, yuegan, yuezhi)
-        Wannianli.update({
-            "yue_gan": yuegan,
-            "yue_zhi": yuezhi,
-        }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
-    print("update month over ", year, month)
+    pass
+    # jieqi = WannianliJieqi.select().where(WannianliJieqi.nianfen == year)
+    # jieqi_day = get_jieqi_of_month(jieqi[0], month)
+    # print("处理", year, month, "月数据, 节气日期是:", jieqi_day)
+    # key_day = str(jieqi_day).split(".")[1]
+    # max_day = get_max_day(year, month)
+    # for day in range(1, max_day + 1):
+    #     if day < int(key_day):
+    #         yuegan = start_yuegan
+    #         yuezhi = start_yuezhi
+    #     else:
+    #         yuegan = next_tiangan(start_yuegan)
+    #         yuezhi = next_dizhi(start_yuezhi)
+    #     # print(year, month, day, yuegan, yuezhi)
+    #     Wannianli.update({
+    #         "yue_gan": yuegan,
+    #         "yue_zhi": yuezhi,
+    #     }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
+    # print("update month over ", year, month)
 
 
 def prepare_yue_data(year: int, month: int):
@@ -101,65 +106,68 @@ def prepare_yue_data(year: int, month: int):
         print("未取得合适的数据", year, month, ",请检查上年12月或本年上个月的数据是否已录入")
         return False
     else:
-        _do_update_yue_by_year(year, month, last_month.yue_gan, last_month.yue_zhi)
+        # _do_update_yue_by_year(year, month, last_month.yue_gan, last_month.yue_zhi)
         return True
 
 
 def update_yue_by_year(year: int):
-    for month in range(1, 13):
-        start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == 1)
-        start_data = start[0]
-        if start_data.yue_gan == "":
-            if not prepare_yue_data(year, month):
-                break
-        else:
-            if year == 1901 and month == 1:
-                _do_update_yue_by_year(year, month, start_data.yue_gan, start_data.yue_zhi)
-            else:
-                if not prepare_yue_data(year, month):
-                    break
+    pass
+    # for month in range(1, 13):
+    #     start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == 1)
+    #     start_data = start[0]
+    #     if start_data.yue_gan == "":
+    #         if not prepare_yue_data(year, month):
+    #             break
+    #     else:
+    #         if year == 1901 and month == 1:
+    #             _do_update_yue_by_year(year, month, start_data.yue_gan, start_data.yue_zhi)
+    #         else:
+    #             if not prepare_yue_data(year, month):
+    #                 break
 
 
 def _do_update_nian_by_year(year: int, start_niangan: str, start_nianzhi: str):
-    jieqi = WannianliJieqi.select().where(WannianliJieqi.nianfen == year)
-    jieqi_key = str(jieqi[0].chuxi).split(".")
-    jieqi_month = int(jieqi_key[0])
-    jieqi_day = int(jieqi_key[1])
-    for month in range(1, 13):
-        max_day = get_max_day(year, month)
-        for day in range(1, max_day + 1):
-            niangan = ""
-            nianzhi = ""
-            if month < jieqi_month:
-                niangan = start_niangan
-                nianzhi = start_nianzhi
-            elif month == jieqi_month:
-                if day > jieqi_day:
-                    niangan = next_tiangan(start_niangan)
-                    nianzhi = next_dizhi(start_nianzhi)
-                else:
-                    niangan = start_niangan
-                    nianzhi = start_nianzhi
-            elif month > jieqi_month:
-                niangan = next_tiangan(start_niangan)
-                nianzhi = next_dizhi(start_nianzhi)
-            Wannianli.update({
-                "nian_gan": niangan,
-                "nian_zhi": nianzhi,
-            }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
-        print(year, month, "年数据更新完成")
+    pass
+    # jieqi = WannianliJieqi.select().where(WannianliJieqi.nianfen == year)
+    # jieqi_key = str(jieqi[0].chuxi).split(".")
+    # jieqi_month = int(jieqi_key[0])
+    # jieqi_day = int(jieqi_key[1])
+    # for month in range(1, 13):
+    #     max_day = get_max_day(year, month)
+    #     for day in range(1, max_day + 1):
+    #         niangan = ""
+    #         nianzhi = ""
+    #         if month < jieqi_month:
+    #             niangan = start_niangan
+    #             nianzhi = start_nianzhi
+    #         elif month == jieqi_month:
+    #             if day > jieqi_day:
+    #                 niangan = next_tiangan(start_niangan)
+    #                 nianzhi = next_dizhi(start_nianzhi)
+    #             else:
+    #                 niangan = start_niangan
+    #                 nianzhi = start_nianzhi
+    #         elif month > jieqi_month:
+    #             niangan = next_tiangan(start_niangan)
+    #             nianzhi = next_dizhi(start_nianzhi)
+    #         Wannianli.update({
+    #             "nian_gan": niangan,
+    #             "nian_zhi": nianzhi,
+    #         }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
+    #     print(year, month, "年数据更新完成")
 
 
 def update_nian_by_year(year: int):
-    start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == 1, Wannianli.ri == 1)
-    start_data = start[0]
-    if start_data.nian_gan == "":
-        print("没有1月1日数据,从上一年取数")
-        last_year = get_wannianli_data(year - 1, 12, 31)
-        if last_year is not None:
-            _do_update_nian_by_year(year, last_year.nian_gan, last_year.nian_zhi)
-    else:
-        _do_update_nian_by_year(year, start_data.nian_gan, start_data.nian_zhi)
+    pass
+    # start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == 1, Wannianli.ri == 1)
+    # start_data = start[0]
+    # if start_data.nian_gan == "":
+    #     print("没有1月1日数据,从上一年取数")
+    #     last_year = get_wannianli_data(year - 1, 12, 31)
+    #     if last_year is not None:
+    #         _do_update_nian_by_year(year, last_year.nian_gan, last_year.nian_zhi)
+    # else:
+    #     _do_update_nian_by_year(year, start_data.nian_gan, start_data.nian_zhi)
 
 
 def get_hour_of_day(day_tiangan: str, hour: int):

+ 44 - 46
main.py

@@ -7,12 +7,11 @@ from fastapi.encoders import jsonable_encoder
 from fastapi.responses import JSONResponse
 from openai import OpenAI
 from pydantic import BaseModel
-from pymysql import OperationalError
 from starlette.middleware.cors import CORSMiddleware
 
+from DBTools import DBUserInfo, DBCustomUser
 from LocalModel import CustomLogin, SaveUser, QueryUser, DeleteUser
 from logic import *
-from model import CustomUser, UserInfo, database
 
 API_KEY = "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"
 
@@ -34,23 +33,6 @@ logging.basicConfig(
 )
 
 
-def check_db_connect():
-    try:
-        database.connect(reuse_if_open=True)
-        dt = CustomUser.select()
-        for item in dt:
-            print(item.id)
-    except OperationalError as e:
-        if 'MySQL server has gone away' in str(e):
-            database.close()
-            database.connect()
-            logging.info("reconnect database")
-    # threading.Timer(60 * 60, check_db_connect).start()
-
-
-# check_db_connect()
-
-
 class Question(BaseModel):
     user: str
     content: str
@@ -220,8 +202,7 @@ async def getSiZhuInfo(request: SiZhuInfoRequest):
 @app.post("/api/customLogin")
 async def customLogin(request: CustomLogin):
     logging.info("login")
-    dt = CustomUser.select().where(CustomUser.user == request.user,
-                                   CustomUser.psd == request.psd).first()
+    dt = DBCustomUser.query_first_by(user=request.user, psd=request.psd)
 
     if dt is not None:
         return {"msg": "ok", "name": dt.name, "sexy": dt.sexy}
@@ -231,14 +212,39 @@ async def customLogin(request: CustomLogin):
 
 @app.post("/api/saveUser")
 async def saveUser(request: SaveUser):
-    ct = UserInfo.select().where(UserInfo.customer == request.customer).count()
-    if ct >= 100:
+    dts = DBUserInfo.query_by(customer=request.customer)
+    if len(dts) >= 100:
         return {"msg": "超过可以保存的用户上限,请联系管理员", "state": -1}
-    UserInfo.insert(request.to_db_data()).execute()
+    from datetime import datetime
+    tm = datetime.now()
+    DBUserInfo.insert(name=request.name,
+                      beizhu=request.beizhu,
+                      man=request.isMan,
+                      leibie=request.leibie,
+                      year=request.year,
+                      month=request.month,
+                      day=request.day,
+                      hour=request.hour,
+                      minute=request.minute,
+                      sheng=request.sheng,
+                      shi=request.shi,
+                      qu=request.qu,
+                      niangan=request.niangan,
+                      nianzhi=request.nianzhi,
+                      yuegan=request.yuegan,
+                      yuezhi=request.yuezhi,
+                      rigan=request.rigan,
+                      rizhi=request.rizhi,
+                      shigan=request.shigan,
+                      shizhi=request.shizhi,
+                      customer=request.customer,
+                      joinTime=tm.strftime("%Y-%m-%d %H:%M:%S"),
+                      enabled=1,
+                      )
     return {"msg": "保存用户信息成功", "state": 200}
 
 
-def __build_user_object(dt: UserInfo):
+def __build_user_object1(dt: DBUserInfo):
     return {
         "id": dt.id,
         "name": dt.name,
@@ -262,20 +268,20 @@ def __build_user_object(dt: UserInfo):
         "shigan": dt.shigan,
         "shizhi": dt.shizhi,
         "customer": dt.customer,
-        "joinTime": dt.join_time
+        "joinTime": dt.joinTime
     }
 
 
 def __do_query_user(customer: str, filter: str):
-    dts = UserInfo.select().where(UserInfo.customer == customer, UserInfo.enabled == 1)
+    dts = DBUserInfo.query_by(customer=customer, enabled=1)
     data = []
     if len(dts) > 0:
         for dt in dts:
             if filter is None:
-                data.append(__build_user_object(dt))
+                data.append(__build_user_object1(dt))
             else:
                 if filter in dt.name:
-                    data.append(__build_user_object(dt))
+                    data.append(__build_user_object1(dt))
     return data
 
 
@@ -287,29 +293,21 @@ async def queryUser(request: QueryUser):
 
 @app.post("/api/deleteUser")
 async def deleteUser(request: DeleteUser):
-    UserInfo.update({"enabled": 0}).where(UserInfo.id == request.id).execute()
+    ss = DBUserInfo.new_session()
+    data = ss.query(DBUserInfo).filter_by(id=request.id).first()
+    if data is not None:
+        data.enabled = 0
+        ss.commit()
+    ss.close()
     return __do_query_user(request.customer, None)
 
 
 @app.post("/api/test")
 async def test(request: Request):
-    request_origin = request.headers.get('origin')
-    if request_origin is None:
-        request_origin = "unknown"
-    content = {"message": "Hello World" + request_origin, "db": "disconnect!!!"}
-    headers = {'Access-Control-Allow-Origin': request_origin}
-    content["db"] = "is_closed: " + str(database.is_closed()) + " is_usable:" + str(database.is_connection_usable())
-    try:
-        dt = CustomUser.select()
-        for item in dt:
-            print(item.name)
-    except Exception as e:
-        logging.info(e)
-    return JSONResponse(content=content, headers=headers)
+    # ContentLogic.createContent()
+    return JSONResponse(content="ok")
 
 
 @app.get("/api/test2")
 async def test2():
-    users = UserInfo.select().where(UserInfo.customer != None)
-    users = [__build_user_object(dt) for dt in users]
-    return {"message": "Hello World", "users": users}
+    return {"message": "Hello World"}

+ 0 - 348
model.py

@@ -17,351 +17,3 @@ class UnknownField(object):
 class BaseModel(Model):
     class Meta:
         database = database
-
-
-class AreaInfo(BaseModel):
-    hour = IntegerField(null=True)
-    jingdu = FloatField(null=True)
-    minute = IntegerField(null=True)
-    qu = TextField(null=True)
-    qu_pinyin = TextField(null=True)
-    second = IntegerField(null=True)
-    sheng = TextField(null=True)
-    shi = TextField(null=True)
-    shi_pinyin = TextField(null=True)
-    weidu = FloatField(null=True)
-
-    class Meta:
-        table_name = 'AreaInfo'
-
-
-class XingGe(BaseModel):
-    key = TextField(null=True)
-    level = IntegerField(null=True)
-    low = TextField()
-    middle = TextField(null=True)
-    strong = TextField(null=True)
-
-    class Meta:
-        table_name = 'XingGe'
-
-
-class CustomUser(BaseModel):
-    name = TextField(null=True)
-    online = IntegerField(null=True)
-    psd = TextField(null=True)
-    sexy = IntegerField(null=True)
-    user = TextField(null=True)
-
-    class Meta:
-        table_name = 'custom_user'
-
-
-class Dashe(BaseModel):
-    dizhi = TextField(null=True)
-    rigan = TextField(null=True)
-    tiangan = TextField(null=True)
-
-    class Meta:
-        table_name = 'dashe'
-
-
-class Diwang(BaseModel):
-    dizhi = TextField(null=True)
-    nianzhi = TextField(null=True)
-    rizhi = TextField(null=True)
-
-    class Meta:
-        table_name = 'diwang'
-
-
-class Dizhi(BaseModel):
-    gan1 = TextField(null=True)
-    gan2 = TextField(null=True)
-    gan3 = TextField(null=True)
-    name = TextField()
-    wuxing = TextField()
-    yinyang_dz = TextField()
-    yuefen = IntegerField()
-
-    class Meta:
-        table_name = 'dizhi'
-
-
-class GaonengMid(BaseModel):
-    arg1 = TextField(null=True)
-    arg2 = TextField(null=True)
-    arg3 = TextField(null=True)
-    desc = TextField(null=True)
-    fangxiang = TextField(null=True)
-    father = TextField(null=True)
-    guanxi = TextField(null=True)
-    hehua = TextField(null=True)
-    leibie = TextField(null=True)
-    tip = TextField(null=True)
-    wuxing1 = TextField(null=True)
-    wuxing2 = TextField(null=True)
-    wuxing3 = TextField(null=True)
-
-    class Meta:
-        table_name = 'gaoneng_mid'
-
-
-class Huagai(BaseModel):
-    dizhi = TextField(null=True)
-    nianzhi = TextField(null=True)
-    rizhi = TextField(null=True)
-
-    class Meta:
-        table_name = 'huagai'
-
-
-class Liuqin(BaseModel):
-    guanxi1 = TextField(null=True)
-    guanxi2 = TextField(null=True)
-    qiankun = TextField(null=True)
-    shishen = TextField(null=True)
-
-    class Meta:
-        table_name = 'liuqin'
-
-
-class LuckyDay(BaseModel):
-    day = IntegerField(null=True)
-    desc = TextField(null=True)
-    jiedu1 = TextField(null=True)
-    jiedu2 = TextField(null=True)
-    jiedu3 = TextField(null=True)
-    jiedu4 = TextField(null=True)
-    jiedu5 = TextField(null=True)
-    month = IntegerField(null=True)
-    riyuan = TextField(null=True)
-    tip = TextField(null=True)
-    year = IntegerField(null=True)
-
-    class Meta:
-        table_name = 'lucky_day'
-
-
-class LushenTip(BaseModel):
-    key = TextField(null=True)
-    tip = TextField(null=True)
-
-    class Meta:
-        table_name = 'lushen_tip'
-
-
-class ShenshaTips(BaseModel):
-    effects = TextField(null=True)
-    shensha = TextField(null=True)
-    tips = TextField(null=True)
-
-    class Meta:
-        table_name = 'shensha_tips'
-
-
-class Shishen(BaseModel):
-    guanxi = TextField()
-    jiancheng = TextField()
-    ta = TextField()
-    ta_wu_xing = TextField(column_name='taWuXing')
-    wo = TextField()
-    wo_wu_xing = TextField(column_name='woWuXing')
-
-    class Meta:
-        table_name = 'shishen'
-
-
-class ShishenGeju(BaseModel):
-    eft = TextField(null=True)
-    key = TextField(null=True)
-    solve = TextField(null=True)
-
-    class Meta:
-        table_name = 'shishen_geju'
-
-
-class ShishenJiedu(BaseModel):
-    arg1 = TextField(null=True)
-    arg2 = TextField(null=True)
-    guanxi = TextField(null=True)
-    tip1 = TextField(null=True)
-    tip2 = TextField()
-    tip3 = TextField(null=True)
-    tip4 = TextField(null=True)
-    tip5 = TextField(null=True)
-
-    class Meta:
-        table_name = 'shishen_jiedu'
-
-
-class ShishenShehuiguanxi(BaseModel):
-    guanxi = TextField(null=True)
-    shishen = TextField(null=True)
-
-    class Meta:
-        table_name = 'shishen_shehuiguanxi'
-
-
-class ShishenZhenjia(BaseModel):
-    jia = TextField(null=True)
-    key = TextField(null=True)
-    zhen = TextField(null=True)
-
-    class Meta:
-        table_name = 'shishen_zhenjia'
-
-
-class Shishenzhilu(BaseModel):
-    dizhi = TextField(null=True)
-    tiangan = TextField(null=True)
-
-    class Meta:
-        table_name = 'shishenzhilu'
-
-
-class Taiyangpianyi(BaseModel):
-    day = IntegerField(null=True)
-    diff = IntegerField(null=True)
-    month = IntegerField(null=True)
-
-    class Meta:
-        table_name = 'taiyangpianyi'
-
-
-class Taohua(BaseModel):
-    dizhi = TextField(null=True)
-    nianzhi = TextField(null=True)
-    rizhi = TextField(null=True)
-
-    class Meta:
-        table_name = 'taohua'
-
-
-class Tiangan(BaseModel):
-    banlu1 = TextField(null=True)
-    banlu2 = TextField(null=True)
-    diwang = TextField()
-    linguan = TextField()
-    lushen = TextField()
-    name = TextField()
-    wenchang = TextField()
-    wuxing = TextField()
-    yinyang = TextField()
-
-    class Meta:
-        table_name = 'tiangan'
-
-
-class Tianyiguiren(BaseModel):
-    dizhi = TextField(null=True)
-    niangan = TextField(null=True)
-    rigan = TextField(null=True)
-
-    class Meta:
-        table_name = 'tianyiguiren'
-
-
-class UserInfo(BaseModel):
-    beizhu = TextField(null=True)
-    customer = TextField(null=True)
-    day = IntegerField(null=True)
-    enabled = IntegerField(null=True)
-    hour = IntegerField(null=True)
-    join_time = TextField(column_name='joinTime', null=True)
-    leibie = IntegerField(null=True)
-    man = IntegerField(null=True)
-    minute = IntegerField(null=True)
-    month = IntegerField(null=True)
-    name = TextField(null=True)
-    niangan = TextField(null=True)
-    nianzhi = TextField(null=True)
-    qu = TextField(null=True)
-    rigan = TextField(null=True)
-    rizhi = TextField(null=True)
-    sheng = TextField(null=True)
-    shi = TextField(null=True)
-    shigan = TextField(null=True)
-    shizhi = TextField(null=True)
-    year = IntegerField(null=True)
-    yuegan = TextField(null=True)
-    yuezhi = TextField(null=True)
-
-    class Meta:
-        table_name = 'user_info'
-
-
-class Wannianli(BaseModel):
-    nian = IntegerField()
-    nian_gan = TextField(null=True)
-    nian_zhi = TextField(null=True)
-    ri = IntegerField()
-    ri_gan = TextField(null=True)
-    ri_zhi = TextField(null=True)
-    yue = IntegerField()
-    yue_gan = TextField(null=True)
-    yue_zhi = TextField(null=True)
-
-    class Meta:
-        table_name = 'wannianli'
-
-
-class WannianliJieqi(BaseModel):
-    bailu = TextField()
-    chuxi = TextField()
-    daxue = TextField()
-    hanlu = TextField()
-    jingzhe = TextField()
-    lichun = TextField()
-    lidong = TextField()
-    liqiu = TextField()
-    lixia = TextField()
-    mangzhong = TextField()
-    nianfen = IntegerField()
-    qingming = TextField()
-    xiaohan = TextField()
-    xiaoshu = TextField()
-
-    class Meta:
-        table_name = 'wannianli_jieqi'
-
-
-class Wuxing(BaseModel):
-    desc1 = TextField(null=True)
-    desc2 = TextField(null=True)
-    effect1 = FloatField(null=True)
-    effect2 = FloatField(null=True)
-    guanxi = TextField(null=True)
-    wuxing1 = TextField(null=True)
-    wuxing2 = TextField(null=True)
-
-    class Meta:
-        table_name = 'wuxing'
-
-
-class Yima(BaseModel):
-    chong = TextField(null=True)
-    dizhi = TextField(null=True)
-    sanhe = TextField(null=True)
-    shoushen = TextField(null=True)
-
-    class Meta:
-        table_name = 'yima'
-
-
-class Zaisha(BaseModel):
-    dizhi = TextField(null=True)
-    nianzhi = TextField(null=True)
-    rizhi = TextField(null=True)
-
-    class Meta:
-        table_name = 'zaisha'
-
-
-class Zhangsheng(BaseModel):
-    dizhi = TextField(null=True)
-    tiangan = TextField(null=True)
-    zhangsheng = TextField(null=True)
-
-    class Meta:
-        table_name = 'zhangsheng'

+ 4 - 3
yixue.py

@@ -14,9 +14,9 @@ import SiZhuLogic
 import SimpleLuckyDay
 import XingGeLogic
 import logic
+from DBTools import DBTaiYangPianYi, DBWanNianLi
 from DataCenter import DataCenter
 from LocalModel import BaZi, SiZhuInfoRequest
-from model import Wannianli, Taiyangpianyi
 
 
 # TODO 入口函数
@@ -73,10 +73,11 @@ def calc_date_of_sizhu(request: SiZhuInfoRequest):
     startDtm = __get_date_time2(request.startDate)
     # print("地区起始时间:", startDtm)
     # print(dtm.year, dtm.month, dtm.day, dtm.hour, dtm.minute, request.weidu, request.jingdu, request.location)
-    dts = Wannianli.select().where(Wannianli.nian == dtm.year, Wannianli.yue == dtm.month, Wannianli.ri == dtm.day)
+    dts = DBWanNianLi.query_by(nian=dtm.year, yue=dtm.month, ri=dtm.day)
+    # dts = Wannianli.select().where(Wannianli.nian == dtm.year, Wannianli.yue == dtm.month, Wannianli.ri == dtm.day)
     # aifs = AreaInfo.select().where(AreaInfo.sheng == request.sheng, AreaInfo.shi == request.shi,
     #                                AreaInfo.qu == request.qu)
-    tys = Taiyangpianyi.select().where(Taiyangpianyi.month == dtm.month, Taiyangpianyi.day == dtm.day)
+    tys = DBTaiYangPianYi.query_by(month=dtm.month, day=dtm.day)
     if len(dts) > 0 and len(tys) > 0:
         # 获得该地区在1月1日0点0分的时间,这个作为基准时间
         # startHour = aifs[0].hour