Esempio n. 1
0
def _topic_snapshot_list(topic):
    if access_public_topic(topic['topics_id']):
        local_mc = mc
        api_key = TOOL_API_KEY
    elif is_user_logged_in():
        local_mc = user_mediacloud_client()
        api_key = user_mediacloud_key()
    else:
        return {}  # prob something smarter we can do here
    snapshots = local_mc.topicSnapshotList(topic['topics_id'])
    snapshots = sorted(snapshots, key=itemgetter('snapshots_id'))
    # add in any missing version numbers
    for idx in range(0, len(snapshots)):
        if snapshots[idx]['note'] in [None, '']:
            snapshots[idx]['note'] = idx + ARRAY_BASE_ONE
    # seed_query story count
    topic['seed_query_story_count'] = _topic_seed_story_count(topic)
    # add foci_count for display
    snapshots = _add_snapshot_foci_count(api_key, topic['topics_id'],
                                         snapshots)
    snapshots = sorted(snapshots, key=lambda d: d['snapshot_date'])
    # extra stuff
    snapshot_status = mc.topicSnapshotGenerateStatus(
        topic['topics_id'])['job_states']  # need to know if one is running
    latest = snapshots[-1] if len(snapshots) > 0 else None
    return {
        'list': snapshots,
        'jobStatus': snapshot_status,
        'latestVersion': latest['note'] if latest else 1,
    }
Esempio n. 2
0
def _topic_snapshot_list(topic):
    local_mc = user_mediacloud_client()
    api_key = user_mediacloud_key()
    snapshots = local_mc.topicSnapshotList(topic['topics_id'])
    snapshots = sorted(snapshots, key=itemgetter('snapshots_id'))
    # add in any missing version numbers
    for idx in range(0, len(snapshots)):
        if snapshots[idx]['note'] in [None, '']:
            snapshots[idx]['note'] = idx + ARRAY_BASE_ONE
    # format any web seed queries as platforms objects
    for s in snapshots:
        platforms = []
        if (s['seed_queries'] is not None) and ('topic' in s['seed_queries']):
            p = platform_for_web_seed_query(s['seed_queries'])
            platforms.append(p)
            platforms += s['seed_queries']['topic_seed_queries']
        else:
            if topic_has_seed_query(topic):
                p = platform_for_web_seed_query(topic)
                platforms.append(p)
        s['platform_seed_queries'] = platforms
    # add foci_count for display
    snapshots = _add_snapshot_foci_count(api_key, topic['topics_id'],
                                         snapshots)
    snapshots = sorted(snapshots, key=lambda d: d['snapshot_date'])
    # extra stuff
    snapshot_status = mc.topicSnapshotGenerateStatus(
        topic['topics_id'])['job_states']  # need to know if one is running
    latest = snapshots[-1] if len(snapshots) > 0 else None
    topic['seed_query_story_count'] = _topic_seed_story_count(topic)
    return {
        'list': snapshots,
        'jobStatus': snapshot_status,
        'latestVersion': latest['note'] if latest else 1,
    }
Esempio n. 3
0
def _topic_summary(topics_id):
    if access_public_topic(topics_id):
        local_mc = mc
    elif is_user_logged_in():
        local_mc = user_admin_mediacloud_client()
    else:
        return jsonify({'status': 'Error', 'message': 'Invalid attempt'})
    topic = local_mc.topic(topics_id)
    # add in snapshot and latest snapshot job status
    topic['snapshots'] = {
        'list': local_mc.topicSnapshotList(topics_id),
        'jobStatus': mc.topicSnapshotGenerateStatus(topics_id)['job_states']    # need to know if one is running
    }
    # add in spider job status
    topic['spiderJobs'] = local_mc.topicSpiderStatus(topics_id)['job_states']
    if is_user_logged_in():
        _add_user_favorite_flag_to_topics([topic])

    '''
    # add in story counts, overall seed and spidered
    feedTotal = topic_story_count(local_mc, topics_id) # with q - but not passed in for summary
    total = topic_story_count(local_mc, topics_id, timespans_id=None, q=None)  # spidered count.. how?
    spidered = total - seedTotal
    topic['seedStories'] = seedTotal
    topic['spideredStories'] = spidered
    topic['totaltories'] = total
    '''
    return topic
Esempio n. 4
0
def _topic_summary(topics_id):
    if access_public_topic(topics_id):
        local_mc = mc
    elif is_user_logged_in():
        local_mc = user_admin_mediacloud_client()
    else:
        return jsonify({'status': 'Error', 'message': 'Invalid attempt'})
    topic = local_mc.topic(topics_id)
    # add in snapshot and latest snapshot job status
    topic['snapshots'] = {
        'list': local_mc.topicSnapshotList(topics_id),
        'jobStatus': mc.topicSnapshotGenerateStatus(topics_id)[
            'job_states']  # need to know if one is running
    }
    if is_user_logged_in():
        _add_user_favorite_flag_to_topics([topic])
    return topic
Esempio n. 5
0
def topic_admin_list():
    user_mc = user_admin_mediacloud_client()
    # if a non-admin user calls this, using user_mc grantees this won't be a security hole
    # but for admins this will return ALL topics
    topics = user_mc.topicList(limit=500)['topics']
    # we also want snapshot info
    for t in topics:
        topics_id = t['topics_id']
        if t['state'] == 'error':
            t['snapshots'] = {
                'list':
                user_mc.topicSnapshotList(topics_id),
                'jobStatus':
                mc.topicSnapshotGenerateStatus(topics_id)[
                    'job_states']  # need to know if one is running
            }

    return jsonify(topics)
Esempio n. 6
0
def _topic_snapshot_worker(topics_id):
    user_mc = user_admin_mediacloud_client()
    return {
        'list': user_mc.topicSnapshotList(topics_id),
        'jobStatus': mc.topicSnapshotGenerateStatus(topics_id)['job_states']  # need to know if one is running
    }
Esempio n. 7
0
def topic_snapshots_list(topics_id):
    user_mc = user_admin_mediacloud_client()
    snapshots = user_mc.topicSnapshotList(topics_id)
    snapshot_status = mc.topicSnapshotGenerateStatus(topics_id)['job_states']    # need to know if one is running
    return jsonify({'list': snapshots, 'jobStatus': snapshot_status})
Esempio n. 8
0
def topic_snapshots_list(topics_id):
    user_mc = user_admin_mediacloud_client()
    snapshots = user_mc.topicSnapshotList(topics_id)
    snapshot_status = mc.topicSnapshotGenerateStatus(topics_id)[
        'job_states']  # need to know if one is running
    return jsonify({'list': snapshots, 'jobStatus': snapshot_status})