def _get_stories(): environment = get_environment() r = redis.StrictRedis( host=environment[REDIS_HOST], port=environment[REDIS_PORT], password=environment[REDIS_PASS] ) return get_stories(r)
def main(): environment = get_environment() connection = yield from asyncio_redis.Connection.create( host=environment[REDIS_HOST], port=environment[REDIS_PORT], password=environment[REDIS_PASS].encode('utf-8'), encoder=BytesEncoder()) top_stories = top_hn_ids() yield from connection.set(TOP_STORIES_KEY, json.dumps(top_stories).encode(u'utf-8')) yield from asyncio.gather(*[ asyncio.Task(cache_story(story_id, connection)) for story_id in top_stories ]) connection.close()
def main(): environment = get_environment() connection = yield from asyncio_redis.Connection.create( host=environment[REDIS_HOST], port=environment[REDIS_PORT], password=environment[REDIS_PASS].encode('utf-8'), encoder=BytesEncoder() ) top_stories = top_hn_ids() yield from connection.set( TOP_STORIES_KEY, json.dumps(top_stories).encode(u'utf-8') ) yield from asyncio.gather( *[asyncio.Task(cache_story(story_id, connection)) for story_id in top_stories] ) connection.close()
def cache_summary_of_url(story_id, title, url, redis_connection): environment = get_environment() redis_key = str(story_id).encode('utf-8') response = yield from redis_connection.get(redis_key) if not response: summary = yield from analyze_url(url, environment[AYLIEN_ID], environment[AYLIEN_KEY]) yield from redis_connection.set( redis_key, json.dumps({ URL: url, TITLE: title, BODY: summary, DATE_FOUND: str(datetime.datetime.now()) }).encode('utf-8')) yield from redis_connection.expire( redis_key, (60 * 60 * 24 * 3) # Expire after 3 days )
def cache_summary_of_url(story_id, title, url, redis_connection): environment = get_environment() redis_key = str(story_id).encode('utf-8') response = yield from redis_connection.get( redis_key ) if not response: summary = yield from analyze_url( url, environment[AYLIEN_ID], environment[AYLIEN_KEY] ) yield from redis_connection.set(redis_key, json.dumps( {URL: url, TITLE: title, BODY: summary, DATE_FOUND: str(datetime.datetime.now())}).encode('utf-8') ) yield from redis_connection.expire( redis_key, (60 * 60 * 24 * 3) # Expire after 3 days )