Fetch the repository succeeded.
Borax 是一个Python3工具集合库。包括了以下几个话题:
话题(Topics) | 内容 |
---|---|
Borax.Calendars | 1900-2100年的中国农历日期库 |
Borax.Choices | 声明式的选项类。适用于Django.models.choices 定义。 |
Borax.Datasets | 记录型数据操作库,包括连结(Join)、列选择(fetch)等 |
Borax.DataStuctures | 树形结构,json数据 |
Borax.Numbers | 数字库。包括中文数字、百分数等。 |
Borax.Patterns | 设计模式。包括单例模式、代理对象、延迟对象。 |
Borax 要求 Python3.5+ 。
可以通过以下两种方式安装 :
$ pip install borax
$ poetry add borax
一个支持1900-2100年的农历日期工具库。
本模块的数据和算法参考自项目 jjonline/calendar.js 。
创建日期,日期推算
from borax.calendars import LunarDate
# 获取今天的农历日期(农历2018年七月初一)
print(LunarDate.today()) # LunarDate(2018, 7, 1, 0)
# 将公历日期转化为农历日期
ld = LunarDate.from_solar_date(2018, 8, 11)
print(ld) # LunarDate(2018, 7, 1, 0)
# 日期推算,返回10天后的农历日期
print(ld.after(10)) # LunarDate(2018, 7, 11, 0)
格式化字符串
today = LunarDate.today()
print(today.strftime('%Y年%L%M月%D')) # '二〇一八年六月廿六'
print(today.strftime('今天的干支表示法为:%G')) # '今天的干支表示法为:戊戌年庚申月辛未日'
分别计算距离 “春节”、“除夕(农历十二月的最后一天)” 还有多少天
from borax.calendars.festivals import get_festival, LunarSchema, DayLunarSchema
festival = get_festival('春节')
print(festival.countdown()) # 7
dls = DayLunarSchema(month=12, day=1, reverse=1)
print(dls.countdown()) # 344
不同形式的中文数字
from borax.numbers import ChineseNumbers
# 小写、计量
print(ChineseNumbers.to_chinese_number(204)) # '二百零四'
# 小写、编号
print(ChineseNumbers.order_number(204)) # '二百〇四'
# 大写、计量
print(ChineseNumbers.to_chinese_number(204, upper=True)) # '贰佰零肆'
# 大写、编号
print(ChineseNumbers.to_chinese_number(204, upper=True, order=True)) # '贰佰〇肆'
财务金额
from borax.numbers import FinanceNumbers
print(FinanceNumbers.to_capital_str(100000000)) # '壹亿元整'
print(FinanceNumbers.to_capital_str(4578442.23)) # '肆佰伍拾柒万捌仟肆佰肆拾贰元贰角叁分'
print(FinanceNumbers.to_capital_str(107000.53)) # '壹拾万柒仟元伍角叁分'
从数据序列中选择一个或多个字段的数据。
from borax.datasets.fetch import fetch
objects = [
{'id': 282, 'name': 'Alice', 'age': 30},
{'id': 217, 'name': 'Bob', 'age': 56},
{'id': 328, 'name': 'Charlie', 'age': 56},
]
names = fetch(objects, 'name')
print(names) # ['Alice', 'Bob', 'Charlie']
文档由 docsify 构建。
源 | 网址 |
---|---|
github | https://kinegratii.github.io/borax |
gitee | https://kinegratii.gitee.io/borax |
The MIT License (MIT)
Copyright (c) 2015-2020 kinegratii
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
如果你觉得这个项目帮助到了你,你可以帮作者们买一杯咖啡表示感谢!
Sign in for post a comment
Activity
Community
Health
Trend
Influence
:Code submit frequency
:React/respond to issue & PR etc.
:Well-balanced team members and collaboration
:Recent popularity of project
:Star counts, download counts etc.
Comments ( 4 )