Ejemplo n.º 1
0
def api_explorer_sources_by_ids():
    source_list = []
    source_id_array = request.args['sources[]'].split(',')
    for media_id in source_id_array:
        info = base_apicache.media(media_id)
        info['id'] = int(media_id)
        source_list.append(info)
    return jsonify({"results": source_list})
Ejemplo n.º 2
0
def api_explorer_story_sample():
    if only_queries_reddit(request.form):
        start_date, end_date = parse_query_dates(request.form)
        provider = RedditPushshiftProvider()
        results = provider.sample(query=request.form['q'],
                                  start_date=start_date, end_date=end_date,
                                  subreddits=NEWS_SUBREDDITS)
    else:
        solr_q, solr_fq = parse_query_with_keywords(request.form)
        results = base_cache.story_list(None, solr_q, solr_fq, rows=SAMPLE_STORY_COUNT,
                                        sort=MediaCloud.SORT_RANDOM)
        for story in results:  # add in media info so we can show it to user if they click into the drill-down
            story["media"] = base_cache.media(story["media_id"])
    return jsonify({"results": results})
Ejemplo n.º 3
0
def api_admin_top_stats(the_type, the_action):
    raw_results = analytics_db.top(the_type, the_action)
    results = []
    for row in raw_results:
        if the_action in row:
            if the_type == analytics_db.TYPE_MEDIA:
                results.append({
                    'item': apicache.media(row['id']),
                    'type': analytics_db.TYPE_MEDIA,
                    'count': row[the_action]
                })
            elif the_type == analytics_db.TYPE_COLLECTION:
                results.append({
                    'item': apicache.collection(row['id']),
                    'type': analytics_db.TYPE_COLLECTION,
                    'count': row[the_action]
                })
    return jsonify({'list': results})
Ejemplo n.º 4
0
def _media_info_worker(info):
    return base_apicache.media(info['key'], info['media_id'])
Ejemplo n.º 5
0
def _media_info_worker(info):
    return base_apicache.media(info['key'], info['media_id'])