Git Product home page Git Product logo

readtime's Introduction

readtime

Tests Coverage

Calculates the time some text takes the average human to read, based on Medium's read time formula.

Algorithm

Medium's Help Center says,

Read time is based on the average reading speed of an adult (roughly 265 WPM). We take the total word count of a post and translate it into minutes, with an adjustment made for images. For posts in Chinese, Japanese and Korean, it's a function of number of characters (500 characters/min) with an adjustment made for images.

Source: https://help.medium.com/hc/en-us/articles/214991667-Read-time (Read Sept 23rd, 2018)

Double checking with real articles, the English algorithm is:

seconds = num_words / 265 * 60 + img_weight * num_images

With img_weight starting at 12 and decreasing one second with each image encountered, with a minium img_weight of 3 seconds.

Installation

virtualenv venv
. venv/bin/activate
pip install readtime

Or if you like to live dangerously:

sudo pip install readtime

Usage

Import readtime and pass it some text, HTML, or Markdown to get back the time it takes to read:

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

The result can also be used as a string:

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

To calculate read time of Markdown:

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

To calculate read time of HTML:

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

To customize the WPM (default 265):

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

Contributing

Before contributing a pull request, make sure tests pass:

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

Many thanks to all contributors!

readtime's People

Contributors

alanhamlett avatar elgalu avatar eumiro avatar guedesfelipe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

readtime's Issues

[Error] Emoji in markdown

Config:

  • macos
  • python 3.10.5
  • lxml 4.9.1
  • beautifulsoup4 4.11.1
  • pyquery 1.4.3

Error in tag.text:

if tag.text and not isinstance(tag, lxml.etree._Comment):

image

I don't know why, but only with this configuration the error appears. I with python 3.8 and 3.9 works perfectly.

More infos you can see here

[Wishlist] ability to define custom WPM as parameter

Hi @alanhamlett,

First of all: a big thank you for the package!
I think it would be a nice addition to make the WPM parameter configurable. Something along the lines of:

result = readtime.of_text('The shortest blog post in the world!', wpm=200)

This would allow you to calculate and get read times as you please. Medium uses 265 WPM but what about technical tutorials or advanced subjects? The WPM will go down and right now there is no easy way to change/define it.

Support for returning custom message

Hi I think it would be nice if it would allow to add custom message instead of returning the default one.
Like when I do readtime on a particular text it returns like "5 min read", it would be good if I can pass a custom message instead or something like "5 minutes read" in full instead.

[feature] Support addition of results

It would be nice to be able to aggregate the reading time of multiple texts.

a = readtime.of_text('hello')
b = readtime.of_text('world')
c = a + b

Which currently errors out with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'Result' and 'Result'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.