Skip to main content

sxtwl_cpp warpper for python

Project description

安装方法

pip install sxtwl

旧工程代码兼容 如果有已使用V1.x版本的工程,想兼容代码

pip install sxtwl==1.1.0

或者在requirements.txt里修改

sxtwl 1.1.0

具体使用方法参考: https://pypi.org/project/sxtwl/

本项目 GitHub / Gitee(码云)

使用方法

  1. 因为考虑到繁体和简体字的原因,所以本库不以硬编码的形式显示结果。下面是参考的简单索引
Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
ShX = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"]
numCn = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑","白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"]
ymc = ["十一", "十二", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十" ]
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
XiZ = ['摩羯', '水瓶', '双鱼', '白羊', '金牛', '双子', '巨蟹', '狮子', '处女', '天秤', '天蝎', '射手']
  1. 引入本库
import  sxtwl

# 从公历年月日获取一天的信息
day = sxtwl.fromSolar(2021, 11, 7) 

# 从农历年月日获取一天的信息
day = sxtwl.fromLunar(2020, 12, 1)
  1. 获取某天的信息(这里的信息有,阴历,阳历,二十四节气,天干地支,星期几等)
# 公历的年月日
s = "公历:%d年%d月%d日" % (day.getSolarYear(), day.getSolarMonth(), day.getSolarDay())
print(s)

# 星期几
print(WeekCn[day.getWeek()])

# 这个月的第几周
print('该日属于这个月的第%d周'%(day.getWeekIndex(),))

# 星座(有bug?待修复)
print("星座:", XiZ[day.getConstellation()])

# 以春节为界的农历(注getLunarYear如果没有传参,或者传true,是以春节为界的)
s = "农历:%d年%s%d月%d日" % (day.getLunarYear(), '闰' if day.isLunarLeap() else '', day.getLunarMonth(), day.getLunarDay())
print(s)

# 不以立春为界的农历
s = "农历:%d年%s%d月%d日" % (day.getLunarYear(False), '闰' if day.isLunarLeap() else '', day.getLunarMonth(), day.getLunarDay())
print(s)


# 以春节为界的天干地支 
yTG = day.getYearGZ(True)
print("以春节为界的年干支", Gan[yTG.tg] + Zhi[yTG.dz]) 
print("以春节为界的生肖:", ShX[yTG.dz])

# 以立春为界的天干地支 (注,如果没有传参,或者传false,是以立春为界的。刚好和getLunarYear相反)
yTG = day.getYearGZ()
print("以立春为界的年干支", Gan[yTG.tg] + Zhi[yTG.dz]) 
print("以立春为界的生肖:", ShX[yTG.dz])

#月干支
mTG = day.getMonthGZ()
print("月干支", Gan[mTG.tg] + Zhi[mTG.dz]) 

#日干支
dTG  = day.getDayGZ()
print("日干支", Gan[dTG.tg] + Zhi[dTG.dz]) 

#时干支
for hour in range(24):
    # 第一个参数为该天的天干,第二个参数为小时
    hTG  = sxtwl.getShiGz(dTG.tg, hour)
    print("%d时天干地支:"%(hour), Gan[hTG.tg] + Zhi[hTG.dz])


# 当日是否有节气
if day.hasJieQi():
    print('节气:%s'% jqmc[day.getJieQi()])
    #获取节气的儒略日数
    jd = day.getJieQiJD()
    # 将儒略日数转换成年月日时秒
    t = sxtwl.JD2DD(jd )

    # 注意,t.s是小数,需要四舍五入
    print("节气时间:%d-%d-%d %d:%d:%d"%(t.Y, t.M, t.D, t.h, t.m, round(t.s)))
else:
    print("当天不是节气日")

  1. 获取某日的前几天或者后几天的信息 (可以用到很多场景中)
# 获取某天的后面几天
num = 1    #你喜欢写多少天 也多少天,可以写负数,相当于往前
day = day.after(num)  #获取num天后的日信息
s = "公历:%d年%d月%d日" % (day.getSolarYear(), day.getSolarMonth(), day.getSolarDay())
print(s)

# 同上
day = day.before(num)
s = "公历:%d年%d月%d日" % (day.getSolarYear(), day.getSolarMonth(), day.getSolarDay())
print(s)
  1. 获取一年中的闰月
# 获取一年中的闰月
year = 2020
month = sxtwl.getRunMonth(year)
if month >= 0:
    print("%d年的闰月是%d"%(year, month) )
else:
    print("没有闰月")
  1. 获取一个农历月的天数
# 一个农历月的天数
year = 2020 #农历年
month  = 4 #农历月
isRun = False #是否是闰月
daynum = sxtwl.getLunarMonthNum(year, month, isRun)
print("农历%d年%s%d月的天数:"%(year, '闰'if isRun else '', month), daynum)

  1. 儒略日数与公历的互转
#儒略日数转公历
jd = sxtwl.J2000
t = sxtwl.JD2DD(jd )

#公历转儒略日
jd = sxtwl.toJD(t)
  1. 查找某日之前或者之后的节气
# 查找某日前后的节气,此例为之后,之前把after替换成before
while True:
    # 这里可以使用after或者before,不用担心速度,这里的计算在底层仅仅是+1这么简单
    day = day.after(1)
    # hasJieQi的接口比getJieQiJD速度要快,你也可以使用getJieQiJD来判断是否有节气。
    if day.hasJieQi():
        print('节气:%s'% jqmc[day.getJieQi()])
        #获取节气的儒略日数, 如果说你要计算什么时间的相距多少,直接比对儒略日要方便,相信我。
        jd = day.getJieQiJD()

        # 将儒略日数转换成年月日时秒
        t = sxtwl.JD2DD(jd )

        # 注意,t.s是小数,需要四舍五入
        print("节气时间:%d-%d-%d %d:%d:%d"%(t.Y, t.M, t.D, t.h, t.m, round(t.s)))

        break
  1. 四柱反查 (好像还有bug,待修复)
# 四注反查 分别传的是年天干,月天干,日天干,时天干, 开始查询年,结束查询年  返回满足条件的儒略日数
jds = sxtwl.siZhu2Year(yTG, mTG, dTG, sxtwl.GZ(7, 5), 2003, 2029);
for jd in jds:
    t = sxtwl.JD2DD(jd )
    print("符合条件的时间:%d-%d-%d %d:%d:%d"%(t.Y, t.M, t.D, t.h, t.m, round(t.s)))

联系作者及广告

作者微信二维码:

微信二维码

请您扫码支持作者的海棠万年历(广告):

海棠万年历

如果您想请作者喝杯奶茶,扫如下微信支付码:

微信收款

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sxtwl-2.0.1.tar.gz (151.3 kB view hashes)

Uploaded Source

Built Distributions

sxtwl-2.0.1-py3.7-macosx-10.9-x86_64.egg (215.2 kB view hashes)

Uploaded Source

sxtwl-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (876.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (876.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (812.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (812.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (617.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (617.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (617.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (595.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (595.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (595.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp39-cp39-macosx_10_15_x86_64.whl (208.1 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

sxtwl-2.0.1-cp38-cp38-win_amd64.whl (173.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

sxtwl-2.0.1-cp38-cp38-win32.whl (157.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

sxtwl-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (620.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (620.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (620.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (597.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (597.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (597.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp38-cp38-macosx_10_15_x86_64.whl (208.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ x86-64

sxtwl-2.0.1-cp37-cp37m-win_amd64.whl (173.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

sxtwl-2.0.1-cp37-cp37m-win32.whl (157.3 kB view hashes)

Uploaded CPython 3.7m Windows x86

sxtwl-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (617.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (617.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (617.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (595.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (595.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (595.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp37-cp37m-macosx_10_15_x86_64.whl (208.6 kB view hashes)

Uploaded CPython 3.7m macOS 10.15+ x86-64

sxtwl-2.0.1-cp36-cp36m-win_amd64.whl (173.4 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

sxtwl-2.0.1-cp36-cp36m-win32.whl (157.3 kB view hashes)

Uploaded CPython 3.6m Windows x86

sxtwl-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (617.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (617.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (617.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.whl (595.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (595.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (595.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp36-cp36m-macosx_10_15_x86_64.whl (208.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.15+ x86-64

sxtwl-2.0.1-cp35-cp35m-win_amd64.whl (173.4 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

sxtwl-2.0.1-cp35-cp35m-win32.whl (157.3 kB view hashes)

Uploaded CPython 3.5m Windows x86

sxtwl-2.0.1-cp35-cp35m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (617.4 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp35-cp35m-manylinux_2_5_i686.manylinux1_i686.whl (595.0 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp35-cp35m-macosx_10_15_x86_64.whl (208.6 kB view hashes)

Uploaded CPython 3.5m macOS 10.15+ x86-64

sxtwl-2.0.1-cp34-cp34m-win_amd64.whl (176.2 kB view hashes)

Uploaded CPython 3.4m Windows x86-64

sxtwl-2.0.1-cp34-cp34m-win32.whl (157.5 kB view hashes)

Uploaded CPython 3.4m Windows x86

sxtwl-2.0.1-cp33-cp33m-win_amd64.whl (177.0 kB view hashes)

Uploaded CPython 3.3m Windows x86-64

sxtwl-2.0.1-cp33-cp33m-win32.whl (158.2 kB view hashes)

Uploaded CPython 3.3m Windows x86

sxtwl-2.0.1-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl (616.2 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp27-cp27mu-manylinux_2_5_i686.manylinux1_i686.whl (596.2 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp27-cp27m-win_amd64.whl (179.2 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

sxtwl-2.0.1-cp27-cp27m-win32.whl (160.6 kB view hashes)

Uploaded CPython 2.7m Windows x86

sxtwl-2.0.1-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (616.2 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.5+ x86-64

sxtwl-2.0.1-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl (596.2 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.5+ i686

sxtwl-2.0.1-cp27-cp27m-macosx_10_15_x86_64.whl (210.1 kB view hashes)

Uploaded CPython 2.7m macOS 10.15+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page