Skip to content

Commit

Permalink
Merge 6c52d46 into 7b19f21
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogutu-Brian committed May 16, 2019
2 parents 7b19f21 + 6c52d46 commit ad4230e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions authors/apps/articles/tests/test_article_read_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class TestReadTime(BaseTest):
def setUp(self):
super().setUp()
self.new_article["body"] = self.word_generator(795)
self.minutes_time = "3 minutes"
self.seconds_time = "3 seconds"
self.minutes_time = "3 minute(s)"
self.seconds_time = "13 second(s)"

def word_generator(self, num_words):
"""
Expand Down
19 changes: 17 additions & 2 deletions authors/utils/article_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ArticleTimer:
def __init__(self, article):
self.article = article
self.words_per_minute = 265
self.image_adjustment_time = round(1/6, 3)

def get_title(self):
"""
Expand Down Expand Up @@ -44,16 +45,30 @@ def get_article_info(self):
info.extend(self.get_tags())
return info

def check_image(self):
"""
Checks whether an article has an image or not
"""
has_image = True
if (self.article.get_image() ==
"No image uploaded") or not self.article.get_image():
has_image = False
self.image_adjustment_time = 0
return has_image

def get_read_time(self):
"""
Gets the read time of the article
"""
word_length = len(self.get_article_info())
read_time = 0
self.check_image()
if word_length:
timer = word_length/self.words_per_minute
if timer < 1:
read_time = str(round(timer*60))+" seconds"
read_time = str(
round((timer+self.image_adjustment_time)*60))+" second(s)"
else:
read_time = str(round(timer))+" minutes"
read_time = str(round(timer+self.image_adjustment_time)) +\
" minute(s)"
return read_time

0 comments on commit ad4230e

Please sign in to comment.