def get(): calendars = Solar.fromDate(datetime.datetime.now()) calendars_str = calendars.toFullString() calendars_Festivals = ','.join(calendars.getFestivals()) + ','.join( calendars.getOtherFestivals()) lunarcakendar = Lunar.fromDate(datetime.datetime.now()) lunarcalendar_year = lunarcakendar.getYearInChinese() lunarcalendar_month = lunarcakendar.getMonthInChinese() lunarcalendar_day = lunarcakendar.getDayInChinese() lunarcakendar_appropriate = ','.join(lunarcakendar.getDayYi()) lunarcakendar_avoid = ','.join(lunarcakendar.getDayJi()) lunarcakendar_Festivals = ','.join( lunarcakendar.getFestivals()) + ','.join( lunarcakendar.getOtherFestivals()) prev = lunarcakendar.getPrevJieQi() prev_JieQi = prev.getName() next = lunarcakendar.getNextJieQi() next_JieQi = "{} {}".format(next.getName(), next.getSolar().toYmdHms()) PengZu = lunarcakendar.getPengZuGan() + ',' + lunarcakendar.getPengZuZhi() CaiShen = lunarcakendar.getDayPositionCai( ) + '-' + lunarcakendar.getDayPositionCaiDesc() FuShen = lunarcakendar.getDayPositionFu( ) + '-' + lunarcakendar.getDayPositionFuDesc() XiShen = lunarcakendar.getDayPositionXi( ) + '-' + lunarcakendar.getDayPositionXiDesc() YuXiang = lunarcakendar.getYueXiang() WuHou = lunarcakendar.getWuHou() res = "今天是:\n" \ "公元>{}\n" \ "阴历>{} {}月 {}\n" \ "宜>{}\n" \ "忌>{}\n" \ "上一节气>{}\n" \ "下一节气>{}\n" \ "传统节日>{}\n" \ "法定节日>{}\n" \ "彭祖百忌>{}\n" \ "财福喜神>财神:{},福神:{},喜神:{}\n" \ "月相>{}\n" \ "今日物候>{}".format( calendars_str, lunarcalendar_year, lunarcalendar_month, lunarcalendar_day, lunarcakendar_appropriate, lunarcakendar_avoid, prev_JieQi, next_JieQi, lunarcakendar_Festivals, calendars_Festivals, PengZu, CaiShen, FuShen, XiShen, YuXiang, WuHou ) return res
# -*- coding: utf-8 -*- from lunar_python import Lunar, Solar from lunar_python.util import HolidayUtil # 节气表 lunar = Solar.fromYmd(2022, 7, 15).getLunar() jieQi = lunar.getJieQiTable() for k in lunar.getJieQiList(): print k + ' = ' + jieQi[k].toYmdHms() print '' # 八字 baZi = lunar.getEightChar() print baZi.getYear() + ' ' + baZi.getMonth() + ' ' + baZi.getDay( ) + ' ' + baZi.getTime() # 八字五行 print baZi.getYearWuXing() + ' ' + baZi.getMonthWuXing( ) + ' ' + baZi.getDayWuXing() + ' ' + baZi.getTimeWuXing() # 八字天干十神 print baZi.getYearShiShenGan() + ' ' + baZi.getMonthShiShenGan( ) + ' ' + baZi.getDayShiShenGan() + ' ' + baZi.getTimeShiShenGan() # 八字地支十神 print baZi.getYearShiShenZhi()[0] + ' ' + baZi.getMonthShiShenZhi( )[0] + ' ' + baZi.getDayShiShenZhi()[0] + ' ' + baZi.getTimeShiShenZhi()[0] # 遍历八字年支十神 for v in baZi.getYearShiShenZhi(): print v
# -*- coding: utf-8 -*- from lunar_python import Lunar, Solar from lunar_python.util import HolidayUtil # 节气表 lunar = Solar.fromYmd(2022, 7, 15).getLunar() jieQi = lunar.getJieQiTable() for k in lunar.getJieQiList(): print k + ' = ' + jieQi[k].toYmdHms() print '' # 八字 baZi = lunar.getEightChar() print baZi.getYear()+' '+baZi.getMonth()+' '+baZi.getDay()+' '+baZi.getTime() # 八字五行 print baZi.getYearWuXing()+' '+baZi.getMonthWuXing()+' '+baZi.getDayWuXing()+' '+baZi.getTimeWuXing() # 八字天干十神 print baZi.getYearShiShenGan()+' '+baZi.getMonthShiShenGan()+' '+baZi.getDayShiShenGan()+' '+baZi.getTimeShiShenGan() # 八字地支十神 print baZi.getYearShiShenZhi()[0]+' '+baZi.getMonthShiShenZhi()[0]+' '+baZi.getDayShiShenZhi()[0]+' '+baZi.getTimeShiShenZhi()[0] # 遍历八字年支十神 for v in baZi.getYearShiShenZhi(): print v print '' # 遍历八字月支十神 for v in baZi.getMonthShiShenZhi():
from lunar_python import Lunar, Solar # 通过指定年月日初始化阳历 solar = Solar.fromYmd(1981, 10, 23) # 通过指定年月日初始化阴历 # lunar = Lunar.fromYmd(1981, 11, 19) lunar = solar.getLunar() # 打印阴历 print(lunar.toFullString()) # 阴历转阳历并打印 print(lunar.getSolar().toFullString())
# 判断day是否是month的最后一天 def isLastDayOfMonth(month, day): if (month == 2 and isLeapYear(YEAR)): return day == leapDay return day == monthLastDayMapping[month] if (isLeapYear(YEAR)): monthLastDayMapping[2] = leapDay else: monthLastDayMapping[2] = nonLeapYearFebLastDay for month in range(1, 13): lastDay = monthLastDayMapping[month] for day in range(1, lastDay + 1): solar = Solar.fromYmd(YEAR, month, day) dates.append(solar) festivals = {'1001': '国庆节'} for date in dates: f = date.getFestivals() + date.getLunar().getFestivals() if len(f): month = str(date.getMonth()) day = str(date.getDay()) festivals[month.zfill(2) + day.zfill(2)] = f[0] # 在这里增加想要添加的节日,可以覆盖掉上面的节日 festivals['0101'] = '元旦' res = []