コード例 #1
0
 def lunar_month(self, date):
     '''
     :param date:date
     :return: lunar month
     '''
     #date = str(date.year)+'-'+str(date.month)+'-'+str(date.day)
     date = dt.datetime.strptime(date, '%Y-%m-%d')
     ln = Lunar(date)
     lunar_date = ln.ln_date()
     return lunar_date[1]
コード例 #2
0
ファイル: generate_image.py プロジェクト: guokai27/Tools
def add_date_words():
    # 日期
    now_year = datetime.datetime.now().year
    today = time.strftime("%Y.%m.%d")
    # 周几
    weekday = get_weekday()
    # 几号
    num = str(int(today.split('.')[-1]))
    # 农历
    # ct = datetime.datetime(2015,2,19,13,0,15)
    # ln = Lunar(ct)
    # print('公历 {}  北京时间 {}'.format(ln.localtime.date(), ln.localtime.time()))
    # print('{} 【{}】 {}年 {}日 {}时'.format(ln.ln_date_str(), ln.gz_year(), ln.sx_year(), ln.gz_day(), ln.gz_hour()))
    # print('节气:{}'.format(ln.ln_jie()))
    ln = Lunar()
    lc_day = ln.gz_year() + '年' + ' ' + ln.ln_date_str()[2:]
    # 已过多少天
    d1 = datetime.datetime.strptime('{}.01.01'.format(now_year), '%Y.%m.%d')
    d2 = datetime.datetime.strptime(today, "%Y.%m.%d")
    delta = (d1 - d2).days
    percent = round(-delta / get_year_days(now_year) * 100, 2)
    delta_days = '第{}天,进度已消耗{}%'.format(-delta, percent)

    font_size = 40
    text_words(font_style, font_size, 40, 40, today)
    text_words(font_style, font_size, w - font_size * 2 - 40, 40,
               weekday)  # 两个字符

    font_size = 130
    temp_height = h * (1 - 0.618) - font_size
    temp_x = get_center_x(1, font_size)
    text_words(font_style, font_size, temp_x, temp_height, num)

    temp_height += font_size
    font_size = 20
    temp_x = get_center_x(7.5, font_size)
    text_words(font_style, font_size, temp_x, temp_height + 10,
               lc_day)  # 7.5字符
    temp_x = get_center_x(11 + len(str(delta)) * 0.5 - 0.5, font_size)
    text_words(font_style, font_size, temp_x, temp_height + font_size + 15,
               delta_days)  # 11 + 0.5/1/1.5字符

    # 进度条
    draw.rectangle((40, 400, w - 40, 440), 'darkgray', 'darkgray')
    draw.rectangle((40, 400, (w - 40 * 2) * percent * 0.01 + 40, 440), color,
                   color)

    gushi = requests.get('https://api.gushi.ci/all.json')

    try:
        data = gushi.json()
        title = data['origin']
        author = data['author']
        content = data['content']
        temp_x = get_center_x(len(title), font_size)
        text_words(font_style, font_size, temp_x, (h - 40 - 500) * 0.2 + 500,
                   title)
        temp_x = get_center_x(len(content), font_size + 2)
        text_words(font_style, font_size + 5, temp_x, 600, content)
        text_words(font_style, font_size,
                   w - (len(author) + 2 + 1) * font_size - 40, 700,
                   '——' + author)
    except:
        print('获取古诗词失败')
コード例 #3
0
ファイル: app.py プロジェクト: AugustLONG/lunar
from lunar import Lunar

app = Lunar('__main__')


@app.route('/', methods=["GET", "POST"])
def index():
    return "Hello, lunar!"


#/args?key=lunar&count=4
@app.route('/test_args', methods=["GET"])
def test_args():
    return app.request.args["key"], app.request.args["count"]

# template


@app.route('/template')
def template():
    return app.render('index.html')


@app.route('/template_with_noescape')
def test_escape():
    return app.render('test_escape.html', content="<p>hello escape</p>")


@app.route('/url_for_with_args')
def test_url_for_with_args():
    return app.url_for(test_sync_args, id=1)
コード例 #4
0
ファイル: app.py プロジェクト: AugustLONG/lunar
from lunar import Lunar

app = Lunar('__main__')


@app.route('/', methods=["GET", "POST"])
def index():
    return "Hello, lunar!"


#/args?key=lunar&count=4
@app.route('/test_args', methods=["GET"])
def test_args():
    return app.request.args["key"], app.request.args["count"]


# template


@app.route('/template')
def template():
    return app.render('index.html')


@app.route('/template_with_noescape')
def test_escape():
    return app.render('test_escape.html', content="<p>hello escape</p>")


@app.route('/url_for_with_args')
def test_url_for_with_args():
コード例 #5
0
ファイル: __init__.py プロジェクト: yuechengzhishang/lunar
from lunar import Lunar
from lunar import database

app = Lunar('blog')
app.config['DATABASE_NAME'] = 'blog.db'

db = database.Sqlite(app.config['DATABASE_NAME'])

from . import views
コード例 #6
0
import pprint
import warnings
from collections import OrderedDict

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
try:
    from lunar import Lunar
except Exception as e:
    warnings.warn(str(e))

_in = input("y,m,d,h,m:")

now = datetime.datetime(*tuple([int(i) for i in _in.split(",")]))
print(now)

a = Lunar(now)

_dict = OrderedDict(
    日期=a.date,
    农历数字=(a.lunarYear, a.lunarMonth, a.lunarDay,
          '闰' if a.isLunarLeapMonth else ''),
    农历='%s %s[%s]年 %s%s' % (a.lunarYearCn, a.year8Char, a.chineseYearZodiac,
                            a.lunarMonthCn, a.lunarDayCn),
    星期=a.weekDayCn,
    # 未增加除夕
    今日节日=(a.get_legalHolidays(), a.get_otherHolidays(),
          a.get_otherLunarHolidays()),
    八字=' '.join([a.year8Char, a.month8Char, a.day8Char, a.twohour8Char]),
    今日节气=a.todaySolarTerms,
    下一节气=(a.nextSolarTerm, a.thisYearSolarTermsDic[a.nextSolarTerm]),
    今年节气表=a.thisYearSolarTermsDic,
コード例 #7
0
ファイル: main.py プロジェクト: imwr/Wox.Plugin.Lunar
 def query(self, query):
     result = []
     try:
         if not query or query == "now":
             ln = Lunar()
         else:
             # 兼容时间戳,如 1473905472000
             if len(query.split(" ")) == 1 and len(query) == 12 or len(
                     query) == 13:
                 try:
                     timenumber = float(query) / 1e3
                     query = str(
                         datetime.datetime.fromtimestamp(timenumber))
                 except ValueError:
                     pass
             ln = Lunar(parse(query))
     except ValueError:
         result.append({
             "Title": 'Can not parse input string',
             "SubTitle":
             'Please input standard date and time format strings',
             "IcoPath": "Images/app.png",
         })
     else:
         jieri = ln.ln_jie()  # 阳历节日
         date = ln.localtime.strftime('%Y-%m-%d %H:%M:%S')  # 当前时间
         notime = False
         if date[11:] == "00:00:00":
             notime = True
         time1 = date[0:11] if notime else date
         result.append({
             "Title":
             time1 + (' 【' + jieri + '】' if jieri else ""),
             "SubTitle":
             ln.localtime.strftime("%A") + " " +
             week_day_dict[ln.localtime.weekday()],
             "IcoPath":
             "Images/app.png",
             "JsonRPCAction": {
                 "method": "add_to_clipboard",
                 "parameters": [time1],
                 "dontHideAfterAction": False
             }
         })
         if datetime.datetime(1901, 1, 1) < ln.localtime:
             jieqi = ln.ln_jieqi()  # 节气
             jieri_lu = ln.ln_jie(True)  # 农历节日
             lutime1 = '{} {}'.format(
                 ln.ln_date_str(), '【' + jieri_lu + '】' if jieri_lu else "")
             lutime2 = '【{}】 {}年-{}日{} {}'.format(
                 ln.sx_year(), ln.gz_year(), ln.gz_day(),
                 ("-" + ln.gz_hour() + "时") if not notime else "",
                 '  节气: ' + jieqi if jieqi else "")
             result.append({
                 "Title": lutime1,
                 "SubTitle": lutime2,
                 "IcoPath": "Images/app.png",
                 "JsonRPCAction": {
                     "method": "add_to_clipboard",
                     "parameters": [lutime1],
                     "dontHideAfterAction": False
                 }
             })
     return result
コード例 #8
0
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
try:
    from lunar import Lunar
except:
    from .lunar import Lunar

import pandas as pd

for y in range(1901, 2100):
    print(f"检查{y}年")
    date_range = pd.date_range(f"{y}0101", f"{y}1231", closed=None)
    for i in date_range:
        dtm = i.to_pydatetime()
        if y in [
                2034,
        ] and dtm in [datetime.datetime(2034, 1, 1)]:
            continue
        l = Lunar(dtm)
        l2 = ZhDate.from_datetime(dtm)
        try:
            assert (l2.lunar_year, l2.lunar_month,
                    l2.lunar_day) == l.get_lunarDateNum()
            assert l2.leap_month == l.isLunarLeapMonth
        except Exception as e:
            print(dtm)
            print((l2.lunar_year, l2.lunar_month, l2.lunar_day), l2.leap_month)
            print(l.get_lunarDateNum(), l.isLunarLeapMonth)
            print(e)
            raise e