예제 #1
0
def read_ophan(section_id = None):

	client = memcache.Client()

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

	if last_read and fresh(last_read): return

	ophan_json = None

	if section_id == 'all':
		ophan_json = ophan.popular()
	else:
		ophan_json = ophan.popular(section_id = section_id)		

	if not ophan_json:
		raise deferred.PermanentTaskFailure()

	ophan_data = json.loads(ophan_json)

	resolved_stories = [resolve_content(entry['url']) for entry in ophan_data]

	resolved_stories = [story for story in resolved_stories if not story == None]

	client = memcache.Client()

	base_key = 'all'

	if section_id: base_key = section_id

	if len(resolved_stories) > 0:
		client.set(base_key, json.dumps(resolved_stories))
		client.set(base_key + '.epoch_seconds', time.time())

	logging.info("Updated data for section %s; listing %d stories" % (section_id, len(resolved_stories)))	
예제 #2
0
	def get(self, entries="5"):
		template = jinja_environment.get_template("most-popular.html")

		cache_key = "ophan_list_popular"

		ophan_list_data = memcache.get(cache_key)

		if not ophan_list_data:
			ophan_list_data = ophan.popular()
			memcache.set(cache_key, ophan_list_data, 60)

		content_list = []

		if ophan_list_data:
			ophan_list = json.loads(ophan_list_data)
			content_list = [content_api.content_id(result['url']) for result in ophan_list]
			content_list = [content_api.read(path, params={"show-fields" : "headline,thumbnail"}) for path in content_list]
			content_list = [json.loads(result) for result in content_list if result]
			content_list = [result["response"]["content"] for result in content_list if content_api.response_ok(result)]
			content_list = content_list[0:int(entries)]

		data ={
			"most_popular" : content_list,
			"component_title" : "Most popular",
		}

		headers.set_cors_headers(self.response)
		self.response.out.write(template.render(data))
예제 #3
0
def read_ophan(section_id=None):

    client = memcache.Client()

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

    if last_read and fresh(last_read): return

    ophan_json = None

    if section_id == 'all':
        ophan_json = ophan.popular()
    else:
        ophan_json = ophan.popular(section_id=section_id)

    if not ophan_json:
        raise deferred.PermanentTaskFailure()

    ophan_data = json.loads(ophan_json)

    resolved_stories = [resolve_content(entry['url']) for entry in ophan_data]

    resolved_stories = [
        story for story in resolved_stories if not story == None
    ]

    client = memcache.Client()

    base_key = 'all'

    if section_id: base_key = section_id

    if len(resolved_stories) > 0:
        client.set(base_key, json.dumps(resolved_stories))
        client.set(base_key + '.epoch_seconds', time.time())

    logging.info("Updated data for section %s; listing %d stories" %
                 (section_id, len(resolved_stories)))