예제 #1
0
파일: heluo.py 프로젝트: yanyizhe/bzengine
def main():
  parser = ArgumentParser(description = 'Calender')
  parser.add_argument('-y', '--year', required = False, help = 'Specify the year to calulate.')
  parser.add_argument('-t', '--time', required = False, help = 'Specify the time to calulate,like: "2014-08-1" or "# "2014-12-01 13:12:12"')
  parser.add_argument('-g', '--gender', required = False, default = 'M', help = 'Specify the gender of the person to calulate, like: "M" or "F"')

  args = parser.parse_args()

  yy = GZTime()
  if args.year:
    yy = GZTime(int(args.year))
  else:
    if not args.time:
      args.time = "1979-11-13 15:20:00"

    print args.time

    tt = None
    try:
      tt = datetime.strptime(args.time,'%Y-%m-%d %X')
    except ValueError as e:
      tt = datetime.strptime(args.time,'%Y-%m-%d')
    yy.setTime(tt)


  if args.gender != 'M' and args.gender != 'F':
    print "Error in gender, it should be 'F' or 'M'."
    return

  gzNumber = HLNumbers(
    args.gender, # 'M' or 'F'
    yy
    )

  gzNumber.dump()
예제 #2
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
  def __init__(self, yy):
    self.yy = yy  # Type is GZTime
    self.st = SolarTerm()
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()

    self.t = []

    # 计算交司时刻

    JQMark  = ("大寒", "春分", "小满", "大暑", "秋分", "小雪", "大寒")
    JQYear  = (yy - 1,  yy,   yy,     yy,    yy,     yy,    yy)

    hi = GZTime.Dizhi.index(self.y_dizhi) % 4


    # 交司时刻表: 申初 午正 巳初 卯正 寅初 子正 亥初 酉正
    JSTable = (15, 12, 9, 6, 3, 0, 21, 18) # 寅午戍年

    # 申子辰年:JSTable[4]开始
    # 巳酉丑年:JSTable[2]开始
    # 寅午戍年:JSTable[0]开始
    # 卯未亥年:JSTable[6]开始
    hoff = [4, 2, 0, 6]

    # for i in xrange(0,7):
      # d = self.st.getJieqiTime(JQYear[i], JQMark[i])
      # d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i]]) + timedelta(days=daysOff[i])
      # print d,JQMark[i]

    for i in xrange(0,7):
      d1 = self.st.getJieqiTime(JQYear[i], JQMark[i])
      d2 = datetime(d1.year, d1.month, d1.day, JSTable[(hoff[hi] + i) % 8])
      self.t.append((d2,JQMark[i]))
예제 #3
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
  def __init__(self, yy):

    self.year = yy
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()
    self.zhongyun = WuYun.ZhongYun[self.y_tiangan]
    self.st = SolarTerm()

    # 中运的初运日为去年的大寒节日
    self.cy_time = self.st.getJieqiTime(yy - 1, "大寒")
    self.cy_gzt = GZTime()
    self.cy_gzt.setTime(self.cy_time)

    # 判断干德符
    self.gdf = self.y_tiangan == self.cy_gzt.getDTiangan() or self.y_tiangan == self.cy_gzt.getHTiangan()
    self.gdfStr = None
    if self.y_tiangan == self.cy_gzt.getDTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的日干相合"

    if self.y_tiangan == self.cy_gzt.getHTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的时干相合"


    # 计算交司时刻
    # 每时辰八刻(初初刻、初一刻、初二刻、初三刻、初四刻、正初刻、正一刻、正二刻、正三刻、正四刻)
    keList =   [0,     144,   1008, 1872,  2736, 3600,  3744,  4608, 5472,  6336]
    keOff = [0, 6, 2, 8, 4]

    hoff = [3, 9, 15, 21]
    JQMark  = ["大寒", "春分", "芒种", "处暑", "立冬"]
    JQYear  = [yy - 1, yy, yy, yy, yy, yy]
    daysOff = [0,      13,     10,     7,     4]
    hi = GZTime.Dizhi.index(self.y_dizhi) % 4
    self.t = []
    for i in xrange(0,6):
      d = self.st.getJieqiTime(JQYear[i], JQMark[i%5])
      d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i%5]]) + timedelta(days=daysOff[i%5])
      self.t.append(d2)
예제 #4
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
  def __init__(self, yy):
    self.year = int(yy)

    # 天干地支时间
    self.gz = GZTime(self.year)

    # 五运
    self.wy = WuYun(self.year)

    # 六气
    self.lq = LiuQi(self.year)

    # 司天气
    self.stq = self.lq.getSiTianZhiQi()

    # 在泉气
    self.zqq = self.lq.getZaiQuanZhiQi()

    # 中运气
    self.zyq = self.wy.getZhongYunZhiQi()
예제 #5
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
class WuYun:
  ZhongYun = {
  "甲": "土运太过--岁土太过,雨湿流行",
  "己": "土运不及--岁土不及,风乃大行",

  "乙": "金运不及--岁金不及,炎火乃行",
  "庚": "金运太过--岁金太过,燥气流行",

  "丙": "水运太过--岁水太过,寒气流行",
  "辛": "水运不及--岁水不及,湿乃大行",

  "丁": "木运不及--岁木不及,燥乃大行",
  "壬": "木运太过--岁木太过,风气流行",

  "戊": "火运太过--岁火太过,炎暑流行",
  "癸": "火运不及--岁火不及,寒乃大行"
  }

  WuYun = "初运 二运 三运 四运 终运".split(' ')

  # 阳干
  # YangGan = ["甲", "丙", "戊", "庚", "壬"]

  def __init__(self, yy):

    self.year = yy
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()
    self.zhongyun = WuYun.ZhongYun[self.y_tiangan]
    self.st = SolarTerm()

    # 中运的初运日为去年的大寒节日
    self.cy_time = self.st.getJieqiTime(yy - 1, "大寒")
    self.cy_gzt = GZTime()
    self.cy_gzt.setTime(self.cy_time)

    # 判断干德符
    self.gdf = self.y_tiangan == self.cy_gzt.getDTiangan() or self.y_tiangan == self.cy_gzt.getHTiangan()
    self.gdfStr = None
    if self.y_tiangan == self.cy_gzt.getDTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的日干相合"

    if self.y_tiangan == self.cy_gzt.getHTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的时干相合"


    # 计算交司时刻
    # 每时辰八刻(初初刻、初一刻、初二刻、初三刻、初四刻、正初刻、正一刻、正二刻、正三刻、正四刻)
    keList =   [0,     144,   1008, 1872,  2736, 3600,  3744,  4608, 5472,  6336]
    keOff = [0, 6, 2, 8, 4]

    hoff = [3, 9, 15, 21]
    JQMark  = ["大寒", "春分", "芒种", "处暑", "立冬"]
    JQYear  = [yy - 1, yy, yy, yy, yy, yy]
    daysOff = [0,      13,     10,     7,     4]
    hi = GZTime.Dizhi.index(self.y_dizhi) % 4
    self.t = []
    for i in xrange(0,6):
      d = self.st.getJieqiTime(JQYear[i], JQMark[i%5])
      d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i%5]]) + timedelta(days=daysOff[i%5])
      self.t.append(d2)
      # print WuYun.WuYun[i%5], " | ", self.t[i]

  # 年的天干地支
  def getYTD(self):
    return self.y_tiangan + self.y_dizhi

  def __str__(self):
    ss =  "中运:" + self.zhongyun + "\n" \
        "初运日: " + str(self.cy_gzt.time) + " : " + str(self.cy_gzt) + "\n"
    if self.gdf:
      ss += "干德符 --> 平气 : " + self.gdfStr
    return ss

  # 五运三纪
  def getWuYunSanJi(self):
    ss = str(self.year) + " 五运三纪: "
    if self.gdf:
      ss += "平气" + " (干德符: " + self.gdfStr + ")"
    else:
      ss += self.zhongyun
    return ss


  def getZhongYun(self):
    i = GZTime.Tiangan.index(self.y_tiangan)
    wy = WuYin(i % 2, i % 5)
    return wy

  def getZhongYunZhiQi(self):
    zy = self.getZhongYun()
    return zy.getQi(), zy.getTaiShao()

  def getKeYun(self):
    i = GZTime.Tiangan.index(self.y_tiangan)
    wy = WuYin(i % 2, i % 5)
    res = []
    for i in xrange(0,5):
      res.append(wy.next(i))
    return res

  def getKeYunList(self):
    kyL = self.getKeYun()
    res = []
    for i in kyL:
      res.append(str(i))
    return res

  def getZhuYunList(self):
    zyL = self.getZhuYun()
    res = []
    for i in zyL:
      res.append(str(i))
    return res

  def getZhuYun(self):
    i = GZTime.Tiangan.index(self.y_tiangan)
    j = i % 5
    wy = WuYin(i % 2, j)
    res = [wy]
    wy2 = wy
    while not wy2.isJiao():
        wy2 = wy2.prev(1)
        res.insert(0,wy2)

    while not wy.isYu():
      wy = wy.next(1)
      res.append(wy)
    return res

  # 五运交司时刻
  def getWuYunTime(self):
    tt = []
    for i in xrange(0,5):
      tt.append(str(self.t[i]) + " - " + str(self.t[i+1]))
    return tt

  def getWuYunTimeFormatStr(self):
    s = "| {0:68}|\n".format("五运交司时刻:")
    for i in xrange(0,5):
      s +=  "| " + WuYun.WuYun[i] +  " : {0:^54} |".format(str(self.t[i]) + " - " + str(self.t[i+1]))
      if i != 4:
        s += "\n"
    return s

  # 相得不相得
  def calcZhuKe(self, zz, kk):
    z = zz.index
    k = kk.index
    if z == k:
      return True, "同气求"
    if ((z+1) % 5) == k:
      return True, "主生客"
    if (z-1) % 5 == k:
      return True, "客生主"
    if (z+2) % 5 == k:
      return False, "主克客"
    if (z-2) % 5 == k:
      return True, "客克主"
    return None

  # 判断主运与客运是否相得
  def getXiangDe(self, zy, ky):
    xd = []
    for i in xrange(0,5):
      xd.append(self.calcZhuKe(zy[i],ky[i]))
    return xd

  def getXiangDeFormatStr(self, zy, ky):
    s = "| 相得   |"
    xd = [None, None, None, None, None]
    for i in xrange(0,5):
      xd[i] = self.calcZhuKe(zy[i], ky[i])
      if xd[i][0]:
        s += " {0:12}".format(xd[i][1])
      else:
        s += " {0:^8} ".format("X")
      s += "|"
    return s

  # 判断主运与客运是否不相得
  def getBuXiangDeFormatStr(self, zy, ky):
    s = "| 不相得 |"
    xd = [None, None, None, None, None]
    for i in xrange(0,5):
      xd[i] = self.calcZhuKe(zy[i], ky[i])
      if not xd[i][0]:
        s += " {0:12}".format(xd[i][1])
      else:
        s += " {0:^8} ".format("X")
      s += "|"
    return s

  def toSimpleJson(self):
    zy = self.getZhuYun()
    ky = self.getKeYun()
    ret = {}
    ret["交司时刻"] = self.getWuYunTime()
    ret["客运"] = self.getKeYunList()
    ret["中运"] = str(self.getZhongYun())
    ret["主运"] = self.getZhuYunList()
    ret["相得"] = self.getXiangDe(zy, ky)
    return ret

  def toString(self):
    zy = self.getZhuYun()
    ky = self.getKeYun()
    ret = ""
    sep = "+---------------------------------------------------------------+"
    ret += sep
    ret += "\n|{0:^65}|".format("五运")
    ret += "\n" + sep
    ret += "\n" + self.getWuYunTimeFormatStr()
    ret += "\n" + sep
    ret += "\n|        |   初运   |   二运   |   三运   |   四运   |   终运   |"
    ret += "\n|  客运  | " + " | ".join(self.getKeYunList()) + " | "
    ret += "\n|  中运  | {0:^56}| ".format(str(self.getZhongYun()))
    ret += "\n|  主运  | " + " | ".join(list2str(zy)) + " | "
    ret += "\n" + sep
    ret += "\n" + self.getXiangDeFormatStr(zy, ky)
    ret += "\n" + self.getBuXiangDeFormatStr(zy, ky)
    ret += "\n" + sep
    return ret
예제 #6
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
class WuYunLiuQi:
  def __init__(self, yy):
    self.year = int(yy)

    # 天干地支时间
    self.gz = GZTime(self.year)

    # 五运
    self.wy = WuYun(self.year)

    # 六气
    self.lq = LiuQi(self.year)

    # 司天气
    self.stq = self.lq.getSiTianZhiQi()

    # 在泉气
    self.zqq = self.lq.getZaiQuanZhiQi()

    # 中运气
    self.zyq = self.wy.getZhongYunZhiQi()

  # 是否天符
  def isTianFu(self):
    return self.zyq[0] == self.stq

  # 是否岁会
  def isSuiHui(self):
    return self.zyq[0] == self.gz.getYSuiqi()

  # 是否同天符: 太过的中运之气 == 在泉之气
  def isTongTianFu(self):
    if self.zyq[1] == "太":
      return self.zyq[0] == self.zqq
    return False

  # 同岁会: 不及的中运之气 == 在泉之气
  def isTongSuiHui(self):
    if self.zyq[1] == "少":
      return self.zyq[0] == self.zqq
    return False

  # 太乙天符
  def isTaiYiTianFu(self):
    return self.isTianFu() and self.isSuiHui()

  def toSimpleJson(self):
    ret = {}
    ret["year"] = self.year
    ret["ganzhi"] = self.wy.getYTD()
    ret["wuyun"] = self.wy.toSimpleJson()
    ret["liuqi"] = self.lq.toSimpleJson()
    ret["special"] = self.getYearSpecial()
    return ret

  def getYearSpecial(self):
    ret = ""
    if self.isTaiYiTianFu():
      ret += "太乙天符 "
    else:
      if self.isTianFu():
        ret += "天符 "
      if self.isSuiHui():
        ret += "岁会 "
    if self.isTongTianFu():
      ret += "同天符 "
    if self.isTongSuiHui():
      ret += "同岁会 "
    return ret.strip()

  def toString(self):
    ret = ""
    ret += str(self.year) + " " + self.wy.getYTD()
    ret += "\n"
    ret += "\n" + str(self.wy.getWuYunSanJi())
    ret += "\n"
    ret += "\n司天气: " + self.stq
    ret += "\n在泉气: " + self.zqq
    ret += "\n中运气: " + self.zyq[1] + self.zyq[0]
    ret += "\n岁支气: " + self.gz.getYSuiqi()

    ss = self.getYearSpecial()
    if len(ss) > 0:
      ret += "\n" + ss

    ret += "\n" + self.wy.toString()
    ret += "\n\n" + self.lq.toString()

    return ret
예제 #7
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
class LiuQi:
  sep = "+--------------------------------------------------------------------------------+"

  # 主气
  ZhuQiName = (
    ("初气" , "厥阴风木"),  # 大寒 立春 雨水 惊蛰 春分 (春分前60日87.5刻)
    ("二气" , "少阴君火"),  # 春分 清明 谷雨 立夏 小满 (春分后60日87.5刻)
    ("三气" , "少阳相火"),  # 小满 芒种 夏至 小暑 大暑 (夏至前后各30日43刻)
    ("四气" , "太阴湿土"),  # 大暑 立秋 处暑 白露 秋分 (秋分前60日87.5刻)
    ("五气" , "阳明燥金"),  # 秋分 寒露 霜降 立冬 小雪 (秋分后60日87.5刻)
    ("终气" , "太阳寒水")   # 小雪 大雪 冬至 小寒 大寒 (冬至前后各30日43刻)
  )

  # 客气顺序
  KeQiName = ("厥阴风木","少阴君火","太阴湿土","少阳相火","阳明燥金","太阳寒水")


  def __init__(self, yy):
    self.yy = yy  # Type is GZTime
    self.st = SolarTerm()
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()

    self.t = []

    # 计算交司时刻

    JQMark  = ("大寒", "春分", "小满", "大暑", "秋分", "小雪", "大寒")
    JQYear  = (yy - 1,  yy,   yy,     yy,    yy,     yy,    yy)

    hi = GZTime.Dizhi.index(self.y_dizhi) % 4


    # 交司时刻表: 申初 午正 巳初 卯正 寅初 子正 亥初 酉正
    JSTable = (15, 12, 9, 6, 3, 0, 21, 18) # 寅午戍年

    # 申子辰年:JSTable[4]开始
    # 巳酉丑年:JSTable[2]开始
    # 寅午戍年:JSTable[0]开始
    # 卯未亥年:JSTable[6]开始
    hoff = [4, 2, 0, 6]

    # for i in xrange(0,7):
      # d = self.st.getJieqiTime(JQYear[i], JQMark[i])
      # d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i]]) + timedelta(days=daysOff[i])
      # print d,JQMark[i]

    for i in xrange(0,7):
      d1 = self.st.getJieqiTime(JQYear[i], JQMark[i])
      d2 = datetime(d1.year, d1.month, d1.day, JSTable[(hoff[hi] + i) % 8])
      self.t.append((d2,JQMark[i]))
      # if i > 0:
      #   print self.t[i][0] - self.t[i-1][0]

  # 司天
  def getSiTian(self):
    i = GZTime.Dizhi.index(self.y_dizhi) % 6
    return LiuQi.KeQiName[(i+1)%6]

  def getSiTianZhiQi(self):
    return self.getSiTian()[-3:]

  def getZaiQuanZhiQi(self):
    return self.getZaiQuan()[-3:]

  # 在泉
  def getZaiQuan(self):
    i = GZTime.Dizhi.index(self.y_dizhi) % 6
    return LiuQi.KeQiName[(i+4)%6]

  def getZhuQiList(self):
    ret = []
    for i in LiuQi.ZhuQiName:
      ret.append(i[1])
    return ret

  def getZhuqiNameFormatStr(self):
    s = "|        |"
    for i in LiuQi.ZhuQiName:
      s += "    " + i[0] + "   |"
    return s

  def getZhuqiFormatStr(self):
    s = "|  主气  |"
    for i in LiuQi.ZhuQiName:
      s += "  " + i[1] + " |"
    return s

  def getZhuqiByIndex(self, i):
    return LiuQi.ZhuQiName[i][1]

  def getKeQiByIndex(self, i):
    j = GZTime.Dizhi.index(self.y_dizhi) % 6
    j = ((j+1)%6 - 2) % 6
    return LiuQi.KeQiName[(j + i) % 6]

  def getXiangDeFormatStr(self):
    for i in xrange(0,6):
      z = self.getZhuqiByIndex(i)
      k = self.getKeQiByIndex(i)
      r = self.calcZhuKe(z,k)

    # TODO

  def calcZhuKe(self, zz, kk):
    T = "木 火 土 金 水".split(" ")
    z = T.index(zz)
    k = T.index(kk)
    if z == k:
      return True, "同气求"
    if ((z+1) % 5) == k:
      return True, "主生客"
    if (z-1) % 5 == k:
      return True, "客生主"
    if (z+2) % 5 == k:
      return False, "主克客"
    if (z-2) % 5 == k:
      return True, "客克主"
    return None

  def getKeQiList(self):
    ret = []
    j = GZTime.Dizhi.index(self.y_dizhi) % 6
    j = ((j+1)%6 - 2) % 6

    for i in xrange(0,6):
      ret.append(LiuQi.KeQiName[(j + i) % 6])
    return ret

  def getKeqiFormatStr(self):
    s = "|  客气  |"
    kqL = self.getKeQiList()

    for i in kqL:
      s += "  " + i + " |"
    return s

  def getJiaoSiShiKe(self):
    ret = []
    for i in xrange(0,6):
      tt = self.t[i][1] + " " + str(self.t[i][0]) + "  -  " + self.t[i+1][1] + " " + str(self.t[i+1][0])
      # ret[LiuQi.ZhuQiName[i][0]] = tt
      ret.append(tt)
    return ret

  def getJiaoSiShiKeStr(self):
    s = "| {0:85}|\n".format("六气交司时刻:")
    for i in xrange(0,6):
      tt = self.t[i][1] + " " + str(self.t[i][0]) + "  -  " + self.t[i+1][1] + " " + str(self.t[i+1][0])
      s +=  "| " + LiuQi.ZhuQiName[i][0] +  " :{0:^76} |".format(tt)
      if i != 5:
        s += "\n"
    return s

  def toSimpleJson(self):
    ret = {}
    ret["交司时刻"] = self.getJiaoSiShiKe()
    ret["司天"] = self.getSiTian()
    ret["在泉"] = self.getZaiQuan()
    ret["客气"] = self.getKeQiList()
    ret["主气"] = self.getZhuQiList()
    return ret

  def toString(self):
    s = LiuQi.sep
    s += "\n"
    s += "|{0:^82}|".format("六气")
    s += "\n" + LiuQi.sep
    s += "\n" + self.getJiaoSiShiKeStr()
    s += "\n" + LiuQi.sep
    s += "\n|        |{0:^41}".format("司天:" + self.getSiTian()) + "|{0:^41}|".format("在泉:" + self.getZaiQuan())
    s += "\n" + LiuQi.sep
    s += "\n" + self.getZhuqiNameFormatStr()
    s += "\n" + self.getKeqiFormatStr()
    s += "\n" + self.getZhuqiFormatStr()
    s += "\n" + LiuQi.sep
    return s