Example #1
0
def updateSummary():

    logging.info("UPDATING SUMMARY")
    query = Summary.all()
    db.delete(query)
    courses = Course.all()
    items = []
    
    for course in courses:
        item = {}
        item['name'] = course.name
        item['id'] = course.cid
        item['hasSept'] = course.hasSeptemberResults
        item['hasFebr'] = course.hasFebruaryResults
        item['hasJune'] = course.hasJuneResults
        item['recent'] = course.nTimesUpdated
        item['addedJune'] = str(course.added_june)
        item['addedSept'] = str(course.added_sept)
        item['addedFebr'] = str(course.added_febr)
        items.append(item)
    
    summary = Summary()
    summary.courses = simplejson.dumps(items)
    summary.put()
    logging.info("FINISHED UPDATING SUMMARY")
Example #2
0
	def get(self):
		template = jinja_environment.get_template('detail.html')
		
		template_values = {}

		today = datetime.date.today()

		twitter_qry = Summary.query(Summary.date == today, Summary.size <= 140).order(-Summary.size, -Summary.count)
		longform_query = Summary.query(Summary.date == today, Summary.size > 140).order(-Summary.size, -Summary.count)
		template_values["twitter"] = twitter_qry.iter()
		template_values["longform"] = longform_query.iter()

		self.response.out.write(template.render(template_values))
Example #3
0
	def get(self, target_date, restriction=None):
		template = jinja_environment.get_template('index.html')
		
		template_values = {}

		cache_key = "today." + target_date

		all_data = memcache.get(cache_key)

		target_day = datetime.datetime.strptime(target_date, '%Y-%m-%d').date()

		if not all_data:

			all_query = Summary.query(Summary.date == target_day, Summary.count > 1).order(-Summary.count)

			all_data = [SummaryInfo(count=x.count, text=x.text, checksum=x.checksum, length=len(x.text)) for x in all_query.iter()]

			try:
				memcache.set(cache_key, all_data, 5 * 60)
			except:
				pass

		template_values["all"] = all_data

		headers.set_cache_headers(self.response, 60)

		self.response.out.write(template.render(template_values))
Example #4
0
    def get(self, target_date, restriction=None):
        template = jinja_environment.get_template('index.html')

        template_values = {}

        cache_key = "today." + target_date

        all_data = memcache.get(cache_key)

        target_day = datetime.datetime.strptime(target_date, '%Y-%m-%d').date()

        if not all_data:

            all_query = Summary.query(Summary.date == target_day,
                                      Summary.count > 1).order(-Summary.count)

            all_data = [
                SummaryInfo(count=x.count,
                            text=x.text,
                            checksum=x.checksum,
                            length=len(x.text)) for x in all_query.iter()
            ]

            try:
                memcache.set(cache_key, all_data, 5 * 60)
            except:
                pass

        template_values["all"] = all_data

        headers.set_cache_headers(self.response, 60)

        self.response.out.write(template.render(template_values))
Example #5
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)
Example #6
0
def read_summary_data(target_date):
	all_query = Summary.query(Summary.date == target_date, Summary.count > 5).order(-Summary.count)

	def summary_as_map(summary):
		return {"count" : x.count,
			"text" : x.text,
			"detail_url" : "http://gu-text-catcher.appspot.com/content/{id}".format(id=x.checksum),
			}

	return [summary_as_map(x) for x in all_query.iter()]
Example #7
0
    def get(self):

        cache_key = "today.all"

        all_data = memcache.get(cache_key)

        today = datetime.date.today()

        if not all_data:

            all_query = Summary.query(Summary.date == today,
                                      Summary.count > 1).order(-Summary.count)

            all_data = [
                SummaryInfo(count=x.count, text=x.text, checksum=x.checksum)
                for x in all_query.iter()
            ]

            memcache.set(cache_key, all_data, 45)

        self.response.out.write("OK")
Example #8
0
	def get(self):
		template = jinja_environment.get_template('index.html')
		
		template_values = {}

		cache_key = "today.all"

		all_data = memcache.get(cache_key)

		today = datetime.date.today()

		if not all_data:

			all_query = Summary.query(Summary.date == today, Summary.count > 1).order(-Summary.count)

			all_data = [SummaryInfo(count=x.count, text=x.text, checksum=x.checksum, length=len(x.text)) for x in all_query.iter()]

		template_values["all"] = all_data

		headers.set_cache_headers(self.response, 60)

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