示例#1
0
	def get(self):

		date = today()
		
		data = {"date" : date}

		data.update(generate_totals(date))

		data.update(reading_time(data))

		if 'wordcount' in data:
			data['literature'] = literature(data['wordcount'])

		headers.json(self.response)
		self.response.out.write(json.dumps(data))
示例#2
0
	def get(self, date):
		logging.info(date)
		template = jinja_environment.get_template('archive.html')
		archive_unavailable_template = jinja_environment.get_template('archive-unavailable.html')

		data = queries.historic_data(date)

		if not data:
			self.response.out.write(archive_unavailable_template.render({"date" : formats.fancy_date(date)}))
			return

		logging.info(data)

		wordcount = reduce(lambda acc, item : acc + item.wordcount, data, 0)

		def section_count(counter, item):
			counter[item.section_id] += item.wordcount
			return counter

		section_counts = reduce(section_count, data, collections.Counter())

		section_data = [(section_id, section_counts[section_id], reading_seconds(section_counts[section_id])) for section_id in section_counts.keys()]

		sorted_section_data = sorted(section_data, reverse = True, key = lambda x : x[1])
		
		template_values = {
			'date' : formats.fancy_date(date),
			'url_date' : formats.url_date(date),
			'data' : data,
			'wordcount' : "{:,d}".format(wordcount),
			'reading_seconds' : reading_seconds(wordcount),
			'sections' : sorted_section_data,
			'literature' : literature(wordcount),
		}

		self.response.out.write(template.render(template_values))