示例#1
0
	def post(self):
		selection = self.request.get("selection")
		selection = selection.lstrip()
		selection = selection.rstrip()

		path = self.request.get("path")

		today = datetime.date.today().isoformat()
		if selection and len(selection) <= 500:
			sha = hashlib.sha1(selection.encode('utf-8')).hexdigest()

			if path:
				CapturedSelection(text=selection, checksum=sha, path=path).put()
			else:
				CapturedSelection(text=selection, checksum=sha).put()

			text_key = ndb.Key("Text", sha)
			text_entity = text_key.get()

			if not text_entity:
				Text(id=sha, text=selection).put()

			count_key_id = today + "." + sha

			count_key = ndb.Key('Summary', count_key_id)

			count = count_key.get()

			if count:
				count.count = count.count + 1
				count.put()
			else:
				Summary(id=count_key_id, text=selection, checksum=sha, count=1, size=len(selection)).put()

		headers.set_cors_headers(self.response, host=CORS_HOST)