根据Medium的阅读时间公式,计算某些文本平均需要人类阅读的时间。
项目描述
readtime
根据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_weight
为 3
秒。
安装
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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 76c5a0d773ad49858c53b42ba3a942f62fbe20cc8c6f07875797ac7dc30963a9 |
|
MD5 | 2097831b78c155e0997c6a6c1b4d4f7d |
|
BLAKE2b-256 | e29fa8e3d08eab31d92e49ef2fe6423ce385503e74f793e0e1a81d343ea991d1 |