解析字符串并提取规范化时间数据。
项目描述
datection
多语言库,用于时间和日期表达式的规范化和渲染。
如何使用它?
规范化
规范化步骤使用特定语言的语法从文本中提取时间表达式,并将它们导出为短、可存储的格式。
示例
>>> import datection
>>> from datetime import datetime
# simple datetime
>>> datection.export(u"Le 4 mars 2015 à 18h30", "fr")
[{'duration': 0,
'rrule': 'DTSTART:20150304\nRRULE:FREQ=DAILY;COUNT=1;BYMINUTE=30;BYHOUR=18',
'span': (0, 23)}]
# date interval with a recurrent exclusion
>>> datection.export(u"Du 5 au 29 mars 2015, sauf le lundi", "fr")
[{'duration': 1439,
'excluded': ['DTSTART:20150305\nRRULE:FREQ=DAILY;BYDAY=MO;BYHOUR=0;BYMINUTE=0;UNTIL=20150329T000000'],
'rrule': 'DTSTART:20150305\nRRULE:FREQ=DAILY;BYHOUR=0;BYMINUTE=0;INTERVAL=1;UNTIL=20150329',
'span': (0, 36)}]
# yearless date, with argument date reference
>>> datection.export(u"Le 4 mars à 18h30", "fr", reference=datetime(2015, 1, 1))
[{'duration': 0,
'rrule': 'DTSTART:20150304\nRRULE:FREQ=DAILY;COUNT=1;BYMINUTE=30;BYHOUR=18',
'span': (0, 18)}]
# past datetime
>>> datection.export(u"Le 4 mars 1990 à 18h30", "fr")
[]
# past datetime and authorized past exports
>>> datection.export(u"Le 4 mars 1990 à 18h30", "fr", only_future=False)
[{'duration': 0,
'rrule': 'DTSTART:19900304\nRRULE:FREQ=DAILY;COUNT=1;BYMINUTE=30;BYHOUR=18',
'span': (0, 18)}]
# continuous datetime interval
>>> datection.export(u"Du 5 avril à 22h au 6 avril 2015 à 8h", "fr")
[{'continuous': True,
'duration': 600,
'rrule': 'DTSTART:20150405\nRRULE:FREQ=DAILY;BYHOUR=22;BYMINUTE=0;INTERVAL=1;UNTIL=20150406T235959',
'span': (0, 38)}]
导出格式
导出格式包含6个不同的项目
-
rrule
:一个可解析的表达式,生成由表达式描述的所有日期时间。有关详细信息,请参阅python-dateutil文档和RFC 2445 -
duration
:由rrule生成的每个开始日期时间与其结束对应时间之间的持续时间(分钟)- 8h → 9h: 持续时间 = 60
- 晚上8点:持续时间 = 0
- 全天:持续时间 = 1439
-
span
:定义时间表达式在文本中找到的字符间隔 -
continuous
:布尔标志,指示时间间隔是否连续。 -
excluded
:包含rrule排除规则的列表。 -
unlimited
:如果为True,则rrule被视为无限。
渲染
渲染步骤将导出格式以特定语言的人类可读格式进行渲染。
可以选择几种格式
- 默认格式
- 短格式:比默认输出更短,在可能的情况下省略一些信息(例如年份),并使结果具有上下文
- 地点:以营业时间的形式显示导出内容
- SEO:合成信息,仅显示月份和年份。用于SEO目的。
>>> import datection
>>> schedule = datection.export(u"Le 5 mars 2015, 15h30 - 16h", "fr")
# default
>>> datection.display(schedule, 'fr')
u'Le 5 mars 2015 de 15 h 30 à 16 h'
# short
>>> datection.display(schedule, 'fr', short=True)
u'Le 5 mars de 15 h 30 à 16 h'
>>> datection.display(schedule, 'fr', short=True, reference=date(2015, 3, 3))
u'Ce jeudi de 15 h 30 à 16 h'
>>> datection.display(schedule, 'fr', short=True, reference=date(2015, 3, 4))
u'Demain de 15 h 30 à 16 h'
>>> datection.display(schedule, 'fr', short=True, reference=date(2015, 3, 5))
u"Aujourd'hui de 15 h 30 ç 16 h"
# SEO
>>> datection.display(schedule, 'fr', seo=True)
u'mars 2015'
# opening hours / place
>>> schedule = datection.export(u"Du lundi au vendredi de 8h à 12h30 et de 14h à 19h30", "fr")
>>> datection.display(schedule, 'fr', place=True)
u"""Lundi de 8 h à 12 h 30 et de 14 h à 19 h 30
Mardi de 8 h à 12 h 30 et de 14 h à 19 h 30
Mercredi de 8 h à 12 h 30 et de 14 h à 19 h 30
Jeudi de 8 h à 12 h 30 et de 14 h à 19 h 30
Vendredi de 8 h à 12 h 30 et de 14 h à 19 h 30
"""
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
datection-4.0.7.tar.gz (114.1 kB 查看散列值)
构建分布
datection-4.0.7-py3-none-any.whl (145.4 kB 查看散列值)
关闭
datection-4.0.7.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 27f868bf03cbbfc73f70123f5f6b498a39fdf204eeefe29f253e80f2d9a950fb |
|
MD5 | b1d868da9ae7f953e496225567f6e29f |
|
BLAKE2b-256 | acbde9a78eb0108160232aef43be8608593eef34b33790b9fd435c0e9cbee68b |
关闭
datection-4.0.7-py3-none-any.whl的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | a6bba5b6a7a0b5a8a6b120d1e4e8574d4c57e21956cf9a7e417c208f5b0edb16 |
|
MD5 | d21a87cb7f41a8ff0c4e9010f7aa06a2 |
|
BLAKE2b-256 | 10a25c1392d01bee4d29fc6000a8f1a3b2bd9714a3801e313bb885e264118632 |