跳转到主要内容

根据Medium的阅读时间公式,计算某些文本平均需要人类阅读的时间。

项目描述

readtime

Tests Coverage

根据Medium的 阅读时间公式 计算某些文本平均需要人类阅读的时间。

算法

Medium的帮助中心表示:

阅读时间基于成年人的平均阅读速度(大约为265词/分钟)。我们将帖子的总词数转换为分钟,并根据图像进行调整。对于中文、日语和韩语帖子,它是基于字符数(500字符/分钟)的函数,并针对图像进行调整。

来源: https://help.medium.com/hc/en-us/articles/214991667-Read-time (阅读日期:2018年9月23日)

通过实际文章的双检查,英文算法是

seconds = num_words / 265 * 60 + img_weight * num_images

img_weight 开始为 12,每次遇到一个图像减少一秒,最小 img_weight3 秒。

安装

virtualenv venv
. venv/bin/activate
pip install readtime

或者如果你喜欢冒险

sudo pip install readtime

用法

导入 readtime 并传递一些文本、HTML或Markdown以获取阅读时间

>>> import readtime
>>> result = readtime.of_text('The shortest blog post in the world!')
>>> result.seconds
2
>>> result.text
u'1 min'

结果也可以用作字符串

>>> str(readtime.of_text('The shortest blog post in the world!'))
u'1 min read'

计算Markdown的阅读时间

>>> readtime.of_markdown('This is **Markdown**')
1 min read

计算HTML的阅读时间

>>> readtime.of_html('This is <strong>HTML</strong>')
1 min read

自定义WPM(默认265)

>>> result = readtime.of_text('The shortest blog post in the world!', wpm=5)
>>> result.seconds
96
>>> result.text
u'2 min'
>>> result.wpm
5

贡献

在贡献拉取请求之前,请确保测试通过

virtualenv venv
. venv/bin/activate
pip install tox
tox

非常感谢所有 贡献者

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

readtime-3.0.0.tar.gz (6.3 kB 查看哈希值)

上传时间

支持者