根据媒体的阅读时间预测,计算一些文本平均需要人类阅读的时间
readtime的Python项目详细描述
#读取时间
[![测试](https://travis-ci.org/alanhamlett/readtime.svg?branch=master)](https://travis-ci.org/alanhamlett/readtime) [![覆盖范围](https://coveralls.io/repos/github/alanhamlett/readtime/badge.svg?branch=master)](https://coveralls.io/github/alanhamlett/readtime?分支=主)
根据medium的[read time forumula](https://help.medium.com/hc/en-us/articles/214991667-Read-time),计算某个文本平均需要人类读取的时间。
###算法
Medium的帮助中心说,
>;阅读时间基于成年人的平均阅读速度(大约265 wpm)。我们把一篇文章的总字数翻译成分钟,并对图片进行调整。对于中文、日文和韩文的帖子,它是一个字符数(500个字符/分钟)的函数,并对图片进行调整。
来源:https://help.medium.com/hc/en-us/articles/214991667-Read-time(2018年9月23日阅读)
与真实文章进行双重检查,英文算法为:
seconds = num_words / 265 * 60 + img_weight * num_images
从12开始,每遇到一个图像,就减少一秒,最小的3秒。
###安装
virtualenv venv . venv/bin/activate pip install readtime
或者如果你喜欢危险的生活:
sudo pip install readtime
###用法
导入read time并传递一些文本、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'
计算标记读取时间:
>>> 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
非常感谢所有的[贡献者](https://github.com/alanhamlett/readtime/blob/master/AUTHORS)!