Exemplo n.º 1
0
	def get(self):
            client = memcache.Client()
            query_str = self.request.query_string
            key = None
            if query_str:
                key = make_key(query_str)
            logging.info(key)    
            if not key:
                key = 'all'
            logging.info(key)
            ophan_json = client.get(key)
            if not ophan_json:
                refresh_data(key)
                ophan_json = "[]"

            last_read = client.get(key + ".epoch_seconds")
            if last_read and not fresh(last_read):
                refresh_data(key)
            
            headers.json(self.response)
            headers.set_cache_headers(self.response, 60)
            headers.set_cors_headers(self.response)

            if 'view=html' in query_str:
                html = generate_html(ophan_json)
                if html is not None:
                    self.response.write(formats.jsonp(self.request, json.dumps({"html" : html})))
                else:
                    self.error(404)
                    self.response.out.write('404 page')    
            else:
                self.response.out.write(formats.jsonp(self.request, ophan_json))
Exemplo n.º 2
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))
Exemplo n.º 3
0
	def get(self):

		profile_path = self.request.get("profile_path", None)
		country = self.request.headers["X-AppEngine-Country"]

		cache_time = 10 * 60
		headers.json(self.response)
		host = "http://www.theguardian.com"
		if gae.is_development():
			host = "*"
		headers.set_cors_headers(self.response, host=host)

		if not profile_path:
			abort(400)

		headers.set_cache_headers(self.response, cache_time)

		key = ndb.Key(Contributor, profile_path)
		contributor = key.get()

		if not contributor:
			abort(404)

		data = {
			"personal" : contributor.twitter_handle,
			"brand" : "guardian",
		}

		if contributor.twitter_brand_handle:
			data['brand'] = contributor.twitter_brand_handle

		self.response.out.write(json.dumps(data))
Exemplo n.º 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))
Exemplo n.º 5
0
	def post(self):

		byline = self.request.get("byline", None)
		country = self.request.headers["X-AppEngine-Country"]

		if not byline:
			abort(400)

		headers.json(self.response)
		headers.set_cors_headers(self.response)
		headers.set_cache_headers(self.response, cache_seconds)

		data = twitter_lookup[byline]

		if not "brand" in data:
			data["brand"] = brand_by_country.get(country, "guardian")

		self.response.out.write(json.dumps(data))
Exemplo n.º 6
0
	def get(self, section_id = None):
		if not section_id: section_id = 'all'

		client = memcache.Client()

		ophan_json = client.get(section_id)
		
		if not ophan_json:
			refresh_data(section_id)
			ophan_json = "[]"

		last_read = client.get(section_id + ".epoch_seconds")

		if last_read and not fresh(last_read):
			refresh_data(section_id)

		headers.json(self.response)
		headers.set_cache_headers(self.response, 60)
		headers.set_cors_headers(self.response)
		self.response.out.write(formats.jsonp(self.request, ophan_json))
Exemplo n.º 7
0
    def get(self, section_id=None):
        if not section_id: section_id = 'all'

        client = memcache.Client()

        ophan_json = client.get(section_id)

        if not ophan_json:
            refresh_data(section_id)
            ophan_json = "[]"

        last_read = client.get(section_id + ".epoch_seconds")

        if last_read and not fresh(last_read):
            refresh_data(section_id)

        headers.json(self.response)
        headers.set_cache_headers(self.response, 60)
        headers.set_cors_headers(self.response)
        self.response.out.write(formats.jsonp(self.request, ophan_json))
Exemplo n.º 8
0
	def get(self, target_date):
		headers.json(self.response)

		cache_key = "json.%s" % target_date

		json_result = memcache.get(cache_key)

		if not json_result:

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

			json_result = json.dumps(read_summary_data(archive_date))

			try:
				memcache.set(cache_key, json_result, 60)
			except:
				pass

		headers.set_cache_headers(self.response, 60)

		self.response.out.write(jsonp(self.request, json_result))
Exemplo n.º 9
0
	def get(self):
		headers.json(self.response)

		cache_key = "json.today"

		json_result = memcache.get(cache_key)

		if not json_result:

			today = datetime.date.today()

			json_result = json.dumps(read_summary_data(today))

			try:
				memcache.set(cache_key, json_result, 60)
			except:
				pass

		headers.set_cache_headers(self.response, 60)

		self.response.out.write(jsonp(self.request, json_result))
Exemplo n.º 10
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))
Exemplo n.º 11
0
    def get(self, edition):

        client = memcache.Client()
        key = edition
        content_json = client.get(key)
        logging.info("content from memcache with key %s" % key)

        if not content_json:
            logging.info("no content found in memcache")
            content_json = content_api.editors_picks(edition)

        editors_picks = (json.loads(content_json)).get('response').get('editorsPicks')
        
        if editors_picks is None:
            logging.warning("could not parse editorsPicks from the response body")
            return_json = content_json   
        else:
            return_json = json.dumps(editors_picks)   

        headers.json(self.response)
        headers.set_cache_headers(self.response, 60)
        headers.set_cors_headers(self.response)
        self.response.out.write(formats.jsonp(self.request, return_json))
Exemplo n.º 12
0
    def get(self):
    	self.response.status = 410
    	headers.set_cache_headers(self.response, 5 * 60)
    	template = jinja_environment.get_template('gone.html')

        self.response.write(template.render({}))
Exemplo n.º 13
0
	def get(self):

		headers.json(self.response)
		headers.set_cors_headers(self.response)
		headers.set_cache_headers(self.response, cache_seconds)
		self.response.out.write(json.dumps(contributors))