def calculate_reading_time(content): wordcount = int(extract.wordcount(content)) readingMinutes = wordcount / 250.0 minutes = math.floor(readingMinutes) seconds = math.floor(60 * (readingMinutes % 1)) content['readingTime'] = "%02d:%02d" % (minutes, seconds) return content
def get(self, minimum): result = {} data = memcache.get("today") if data: all_content = json.loads(data) at_least = lambda x: int(extract.wordcount(x)) >= int(minimum) * 250 valid_filter = lambda x: data_filters.has_wordcount(x) and at_least(x) and data_filters.valid_section(x) appropriate_content = [calculate_reading_time(i) for i in all_content if valid_filter(i)] sorted_content = sorted(appropriate_content, key = lambda x: int(extract.wordcount(x)), reverse = True) result['content'] = sorted_content headers.json(self.response) self.response.out.write(json.dumps(result))
def get(self): template = jinja_environment.get_template('index.html') template_values = {} data = memcache.get("today") if data: all_content = json.loads(data) valid_filter = lambda x: data_filters.has_wordcount(x) and data_filters.minutes(0, 5)(x) and data_filters.valid_section(x) five_minute_content = filter(valid_filter, all_content) template_values['content'] = sorted(five_minute_content, key = lambda x: extract.wordcount(x), reverse = True) self.response.out.write(template.render(template_values))
def minutes(min, max): return lambda x : min * 250 <= int(extract.wordcount(x)) <= max * 250