根据媒体的阅读时间预测,计算一些文本平均需要人类阅读的时间

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)!

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
现代Java编译器/JVM内联函数/方法完全从一个地方调用,性能如何?   java为什么JComponents不出现在框架中?   Java输入字母   java从Listview获取所选行号   日志无法使用java为JBOSS EAP 7实现log4j?   通过SSE订阅的java Flux引发取消()事件   java spring启动entityManagerFactory登录后初始化   java如何获取单链表来对十六进制数进行排序   (RippledRavable)上的java endAllStagingAnimators,句柄位于RecyclerView上   java在计时器触发后唤醒Android屏幕   java如何使代码“面向对象”,以便在带有CLOB的ArrayList中使用变量   将Java连接传递给多个公共函数的sql安全问题   java Bean创建错误   HttpRequest的参数在Java中的默认编码(Tomcat)   java为什么可绘制背景在大视图中消失?