def _cached_popular_collections(): popular_collections = [] for tagsId in POPULAR_COLLECTION_LIST: info = mc.tag(tagsId) info['id'] = tagsId popular_collections += [info] return popular_collections
def _cached_featured_collections(): featured_collections = [] for tags_id in FEATURED_COLLECTION_LIST: coll = mc.tag(tags_id) coll['id'] = tags_id source_count_estimate = _cached_media_with_tag_page(tags_id, 0) coll['media_count'] = len(source_count_estimate) how_lively_is_this_collection = 0 # story count for media in source_count_estimate: one_weeks_before_now = datetime.datetime.now() - datetime.timedelta(days=7) start_date = one_weeks_before_now end_date = datetime.datetime.now() publish_date = mc.publish_date_query(start_date, end_date, True, True) media_query = "(media_id:{})".format(media['media_id']) + " AND (+" + publish_date + ")" how_lively_is_this_collection += _cached_source_story_count(user_mediacloud_key(), media_query) # approximate liveliness - if there are more stories than 100, we know this is a reasonably active source/collection if how_lively_is_this_collection > 100: break coll['story_count'] = how_lively_is_this_collection featured_collections.append(coll) return featured_collections
def api_explorer_demo_collections_by_ids(): collection_ids = request.args['collections[]'].split(',') coll_list = [] for tags_id in collection_ids: if len(tags_id) > 0: info = mc.tag(tags_id) info['id'] = tags_id coll_list.append(info) return jsonify({"results": coll_list})
def api_explorer_demo_collections_by_ids(): collection_ids = request.args['collections[]'].split(',') coll_list = [] for tags_id in collection_ids: if len(tags_id) > 0: info = mc.tag(tags_id) info['id'] = tags_id coll_list.append(info) return jsonify({"results": coll_list})
def api_explorer_collections_by_ids(): collIdArray = request.args['collections[]'].split(',') coll_list = [] for tagsId in collIdArray: info = mc.tag(tagsId) info['id'] = tagsId # info['tag_set'] = _tag_set_info(mc, info['tag_sets_id']) coll_list.append(info); return jsonify(coll_list)
def _cached_featured_collections(): featured_collections = [] for tagsId in FEATURED_COLLECTION_LIST: info = mc.tag(tagsId) info['id'] = tagsId # use None here to use app-level mc object info['wordcount'] = cached_wordcount(None, 'tags_id_media:' + str(tagsId)) featured_collections += [info] return featured_collections
def api_explorer_demo_collections_by_ids(): collection_ids = request.args['collections[]'].split(',') coll_list = [] for tags_id in collection_ids: tags_id = tags_id.encode( 'ascii', 'ignore') # if empty, the unicode char will cause an error if len(tags_id) > 0: info = mc.tag(tags_id) info['id'] = tags_id # info['tag_set'] = _tag_set_info(mc, info['tag_sets_id']) coll_list.append(info) return jsonify(coll_list)
def _cached_featured_collection_list(tag_id_list): use_pool = True add_source_counts = False featured_collections = [] for tags_id in tag_id_list: coll = mc.tag(tags_id) coll['id'] = tags_id featured_collections.append(coll) if add_source_counts: if use_pool: pool = Pool(processes=STORY_COUNT_POOL_SIZE) set_of_queried_collections = pool.map(collection_details_worker, featured_collections) pool.close() else: set_of_queried_collections = [collection_details_worker(c) for c in featured_collections] else: set_of_queried_collections = featured_collections return set_of_queried_collections
def _cached_featured_collection_list(tag_id_list): use_pool = True add_source_counts = False featured_collections = [] for tags_id in tag_id_list: coll = mc.tag(tags_id) coll['id'] = tags_id featured_collections.append(coll) if add_source_counts: if use_pool: pool = Pool(processes=STORY_COUNT_POOL_SIZE) set_of_queried_collections = pool.map(collection_details_worker, featured_collections) pool.close() else: set_of_queried_collections = [collection_details_worker(c) for c in featured_collections] else: set_of_queried_collections = featured_collections return set_of_queried_collections
def _cached_featured_collection_list(): return [mc.tag(tags_id) for tags_id in FEATURED_COLLECTION_LIST]
def _cached_featured_collection_list(): return [mc.tag(tags_id) for tags_id in FEATURED_COLLECTION_LIST]