本文整理汇总了Python中server.auth.user_mediacloud_key函数的典型用法代码示例。如果您正苦于以下问题:Python user_mediacloud_key函数的具体用法?Python user_mediacloud_key怎么用?Python user_mediacloud_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_mediacloud_key函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: topic_compare_subtopic_top_words
def topic_compare_subtopic_top_words(topics_id):
snapshots_id, timespans_id, foci_id, q = filters_from_args(request.args)
selected_focal_sets_id = request.args['focal_sets_id']
word_count = request.args['word_count'] if 'word_count' in request.args else 20
# first we need to figure out which timespan they are working on
selected_snapshot_timespans = apicache.cached_topic_timespan_list(user_mediacloud_key(), topics_id,
snapshots_id=snapshots_id)
selected_timespan = None
for t in selected_snapshot_timespans:
if t['timespans_id'] == int(timespans_id):
selected_timespan = t
try:
focal_set = apicache.topic_focal_set(user_mediacloud_key(), topics_id, snapshots_id, selected_focal_sets_id)
except ValueError:
return json_error_response('Invalid Focal Set Id')
timespans = apicache.matching_timespans_in_foci(topics_id, selected_timespan, focal_set['foci'])
for idx in range(0, len(timespans)):
data = apicache.topic_word_counts(user_mediacloud_key(), topics_id,
timespans_id=timespans[idx]['timespans_id'])
focal_set['foci'][idx]['top_words'] = data
# stitch together the counts to download now
data = []
headers = [f['name'] for f in focal_set['foci']]
for idx in range(0, word_count):
row = {f['name']: "{} ({})".format(f['top_words'][idx]['term'], f['top_words'][idx]['count'])
for f in focal_set['foci']}
data.append(row)
return csv.stream_response(data, headers,
'topic-{}-subtopic-{}-{}-top-words-comparison'.format(
topics_id, focal_set['name'], selected_focal_sets_id))
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:30,代码来源:words.py
示例2: get_top_countries_by_story_tag_counts
def get_top_countries_by_story_tag_counts(topics_id, num_countries):
tag_country_counts = []
# get the total stories for a topic
total_stories = topic_story_count(user_mediacloud_key(), topics_id)['count']
# get the top countries by the story tag counts iwth overall timespan
timespans = cached_topic_timespan_list(user_mediacloud_key(), topics_id)
overall_timespan = [t for t in timespans if t['period'] == "overall"]
overall_timespan = next(iter(overall_timespan))
timespan_query = "timespans_id:{}".format(overall_timespan['timespans_id'])
top_geo_tags = _cached_topic_tag_counts(user_mediacloud_key(), topics_id, GEO_TAG_SET, GEO_SAMPLE_SIZE, timespan_query)
# make sure the geo tag is in the geo_tags whitelist (is a country)
country_tag_counts = [r for r in top_geo_tags if
int(r['tag'].split('_')[1]) in list(COUNTRY_GEONAMES_ID_TO_APLHA3.keys())]
country_tag_counts = country_tag_counts[:num_countries]
# for each country, set up the requisite info for UI
for tag in country_tag_counts:
tag_country_counts.append({
'label': tag['label'],
'geo_tag': tag['tag'],
'tags_id': tag['tags_id'],
'count': tag['count'],
'pct': float(tag['count']) / float(total_stories), # story_tag_count / total story per topic count
})
return tag_country_counts
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:28,代码来源:topcountries.py
示例3: topic_words
def topic_words(topics_id):
sample_size = request.args['sample_size'] if 'sample_size' in request.args else WORD_COUNT_SAMPLE_SIZE
if access_public_topic(topics_id):
results = apicache.topic_word_counts(TOOL_API_KEY, topics_id, sample_size=sample_size,
snapshots_id=None, timespans_id=None, foci_id=None, q=None)
elif is_user_logged_in():
# grab the top words, respecting all the filters
results = apicache.topic_word_counts(user_mediacloud_key(), topics_id, sample_size=sample_size)
else:
return jsonify({'status': 'Error', 'message': 'Invalid attempt'})
totals = [] # important so that these get reset on the client when they aren't requested
logger.debug(request.args)
if (is_user_logged_in()) and ('withTotals' in request.args) and (request.args['withTotals'] == "true"):
# return along with the results for the overall timespan, to facilitate comparison
snapshots_id, timespans_id, foci_id, q = filters_from_args(request.args)
overall_timespan = _find_overall_timespan(topics_id, snapshots_id)
totals = apicache.topic_word_counts(user_mediacloud_key(), topics_id, sample_size=sample_size,
timespans_id=overall_timespan['timespans_id'], foci_id=None, q=None)
response = {
'list': results[:WORD_COUNT_UI_NUM_WORDS],
'totals': totals[:WORD_COUNT_UI_NUM_WORDS],
'sample_size': str(sample_size)
}
return jsonify(response)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:27,代码来源:words.py
示例4: collection_update
def collection_update(collection_id):
user_mc = user_admin_mediacloud_client()
label = '{}'.format(request.form['name'])
description = request.form['description']
static = request.form['static'] if 'static' in request.form else None
show_on_stories = request.form['showOnStories'] if 'showOnStories' in request.form else None
show_on_media = request.form['showOnMedia'] if 'showOnMedia' in request.form else None
formatted_name = format_name_from_label(label)
source_ids = []
if len(request.form['sources[]']) > 0:
source_ids = [int(sid) for sid in request.form['sources[]'].split(',')]
# first update the collection
updated_collection = user_mc.updateTag(collection_id, formatted_name, label, description,
is_static=(static == 'true'),
show_on_stories=(show_on_stories == 'true'),
show_on_media=(show_on_media == 'true'))
# get the sources in the collection first, then remove and add as needed
existing_source_ids = [int(m['media_id']) for m in media_with_tag(user_mediacloud_key(), collection_id)]
source_ids_to_remove = list(set(existing_source_ids) - set(source_ids))
source_ids_to_add = [sid for sid in source_ids if sid not in existing_source_ids]
# logger.debug(existing_source_ids)
# logger.debug(source_ids_to_add)
# logger.debug(source_ids_to_remove)
# then go through and tag all the sources specified with the new collection id
tags_to_add = [MediaTag(sid, tags_id=collection_id, action=TAG_ACTION_ADD) for sid in source_ids_to_add]
tags_to_remove = [MediaTag(sid, tags_id=collection_id, action=TAG_ACTION_REMOVE) for sid in source_ids_to_remove]
tags = tags_to_add + tags_to_remove
if len(tags) > 0:
user_mc.tagMedia(tags)
apicache.invalidate_collection_source_representation_cache(user_mediacloud_key(), collection_id)
return jsonify(updated_collection['tag'])
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:33,代码来源:collectionedit.py
示例5: get_top_themes_by_story_tag_counts
def get_top_themes_by_story_tag_counts(topics_id, num_themes):
user_mc_key = user_mediacloud_key()
nyt_counts = []
#get overall timespan
timespans = cached_topic_timespan_list(user_mediacloud_key(), topics_id)
overall_timespan = [t for t in timespans if t['period'] == "overall"]
overall_timespan = next(iter(overall_timespan))
timespan_query = "timespans_id:{}".format(overall_timespan['timespans_id'])
# get the top themes by the story counts iwth overall timespan
top_nyt_tags = _cached_topic_tag_counts(user_mediacloud_key(), topics_id, NYT_LABELS_TAG_SET_ID,
TAG_COUNT_SAMPLE_SIZE, timespan_query)
# get the total stories for a topic
total_stories = topic_story_count(user_mediacloud_key(), topics_id)['count']
top_nyt_tags = top_nyt_tags[:num_themes]
# for each country, set up the requisite info for UI
for tag in top_nyt_tags:
nyt_counts.append({
'label': tag['label'],
'geo_tag': tag['tag'],
'tags_id': tag['tags_id'],
'count': tag['count'],
'pct': float(tag['count']) / float(total_stories), #story_tag_count / total story per topic count
})
return nyt_counts
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:28,代码来源:nyttheme.py
示例6: media_type_coverage
def media_type_coverage(topics_id):
media_type_tags = tags_in_tag_set(TOOL_API_KEY, TAG_SETS_ID_MEDIA_TYPE)
# grab the total stories
total_stories = topic_story_count(user_mediacloud_key(), topics_id)['count']
# count the stories in any media in tagged as media_type
tags_ids = " ".join(str(tag['tags_id']) for tag in media_type_tags)
query_clause = "tags_id_media:({})".format(tags_ids)
tagged_story_count = topic_story_count(user_mediacloud_key(), topics_id, q=query_clause)['count']
return jsonify({'counts': {'count': tagged_story_count, 'total': total_stories}})
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:9,代码来源:mediatype.py
示例7: _public_safe_topic_story_count
def _public_safe_topic_story_count(topics_id, q):
if access_public_topic(topics_id):
total = apicache.topic_story_count(TOOL_API_KEY, topics_id, q=apicache.add_to_user_query(None))
# force a count with just the query
matching = apicache.topic_story_count(TOOL_API_KEY, topics_id, q=apicache.add_to_user_query(q))
elif is_user_logged_in():
total = apicache.topic_story_count(user_mediacloud_key(), topics_id, q=apicache.add_to_user_query(None))
# force a count with just the query
matching = apicache.topic_story_count(user_mediacloud_key(), topics_id, q=apicache.add_to_user_query(q))
else:
return jsonify({'status': 'Error', 'message': 'Invalid attempt'})
return jsonify({'counts': {'count': matching['count'], 'total': total['count']}})
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:12,代码来源:stories.py
示例8: api_collection_details
def api_collection_details(collection_id):
add_in_sources = False
if ('getSources' in request.args) and (request.args['getSources'] == 'true'):
add_in_sources = True
user_mc = user_mediacloud_client()
info = user_mc.tag(collection_id)
add_user_favorite_flag_to_collections([info])
info['id'] = collection_id
info['tag_set'] = _tag_set_info(user_mediacloud_key(), info['tag_sets_id'])
if add_in_sources:
media_in_collection = media_with_tag(user_mediacloud_key(), collection_id)
info['sources'] = media_in_collection
analytics_db.increment_count(analytics_db.TYPE_COLLECTION, collection_id, analytics_db.ACTION_SOURCE_MGR_VIEW)
return jsonify({'results': info})
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:15,代码来源:collection.py
示例9: api_collection_sources_csv
def api_collection_sources_csv(collection_id):
user_mc = user_mediacloud_client()
collection = user_mc.tag(collection_id) # not cached because props can change often
all_media = media_with_tag(user_mediacloud_key(), collection_id)
file_prefix = "Collection {} ({}) - sources ".format(collection_id, collection['tag'])
properties_to_include = SOURCE_LIST_CSV_EDIT_PROPS
return csv.download_media_csv(all_media, file_prefix, properties_to_include)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:7,代码来源:collection.py
示例10: api_collection_source_representation_csv
def api_collection_source_representation_csv(collection_id):
user_mc = user_mediacloud_client()
info = user_mc.tag(collection_id)
source_representation = apicache.collection_source_representation(user_mediacloud_key(), collection_id)
props = ['media_id', 'media_name', 'media_url', 'stories', 'sample_size', 'story_pct']
filename = info['label'] + "-source sentence counts.csv"
return csv.stream_response(source_representation, props, filename)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:7,代码来源:collection.py
示例11: collection_wordcount_csv
def collection_wordcount_csv(collection_id):
solr_q = 'tags_id_media:' + str(collection_id)
solr_fq = None
# add in the publish_date clause if there is one
if ('q' in request.args) and (len(request.args['q']) > 0):
solr_fq = request.args['q']
return stream_wordcount_csv(user_mediacloud_key(), 'wordcounts-Collection-' + collection_id, solr_q, solr_fq)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:7,代码来源:collection.py
示例12: _find_overall_timespan
def _find_overall_timespan(topics_id, snapshots_id):
selected_snapshot_timespans = apicache.cached_topic_timespan_list(user_mediacloud_key(), topics_id,
snapshots_id=snapshots_id)
for timespan in selected_snapshot_timespans:
if timespan['period'] == 'overall':
return timespan
raise RuntimeError('Missing overall timespan in snapshot {} (topic {})!'.format(snapshots_id, topics_id))
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:7,代码来源:words.py
示例13: api_metadata_values
def api_metadata_values(tag_sets_id):
'''
Source metadata is encoded in various tag sets - this returns the set and the list of
available tags you can use
'''
data = tags_in_tag_set(user_mediacloud_key(), tag_sets_id, False, True) # use the file-based cache here
return jsonify(data)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:7,代码来源:metadata.py
示例14: media_words_csv
def media_words_csv(topics_id, media_id):
query = apicache.add_to_user_query('media_id:'+media_id)
ngram_size = request.args['ngram_size'] if 'ngram_size' in request.args else 1 # default to word count
word_counts = apicache.topic_ngram_counts(user_mediacloud_key(), topics_id, ngram_size=ngram_size, q=query,
num_words=WORD_COUNT_DOWNLOAD_NUM_WORDS,
sample_size=WORD_COUNT_DOWNLOAD_SAMPLE_SIZE)
return csv.stream_response(word_counts, apicache.WORD_COUNT_DOWNLOAD_COLUMNS,
'topic-{}-media-{}-sampled-ngrams-{}-word'.format(topics_id, media_id, ngram_size))
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:8,代码来源:media.py
示例15: media
def media(topics_id, media_id):
user_mc = user_admin_mediacloud_client()
combined_media_info = apicache.topic_media_list(user_mediacloud_key(), topics_id, media_id=media_id)['media'][0]
media_info = user_mc.media(media_id)
for key in list(media_info.keys()):
if key not in list(combined_media_info.keys()):
combined_media_info[key] = media_info[key]
return jsonify(combined_media_info)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:8,代码来源:media.py
示例16: media_type_story_counts
def media_type_story_counts(topics_id):
tag_story_counts = []
media_type_tags = tags_in_tag_set(TOOL_API_KEY, TAG_SETS_ID_MEDIA_TYPE)
# grab the total stories
total_stories = topic_story_count(user_mediacloud_key(), topics_id)['count']
# make a count for each tag based on media_id
for tag in media_type_tags:
query_clause = "tags_id_media:{}".format(tag['tags_id'])
tagged_story_count = topic_story_count(user_mediacloud_key(), topics_id, q=query_clause)['count']
tag_story_counts.append({
'label': tag['label'],
'tags_id': tag['tags_id'],
'count': tagged_story_count,
'pct': float(tagged_story_count)/float(total_stories)
})
return jsonify({'story_counts': tag_story_counts})
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:17,代码来源:mediatype.py
示例17: _collection_source_story_split_historical_counts
def _collection_source_story_split_historical_counts(collection_id):
media_list = media_with_tag(user_mediacloud_key(), collection_id)
jobs = [{'media': m} for m in media_list]
# fetch in parallel to make things faster
pool = Pool(processes=HISTORICAL_COUNT_POOL_SIZE)
results = pool.map(_source_story_split_count_worker, jobs) # blocks until they are all done
pool.terminate() # extra safe garbage collection
return results
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:8,代码来源:collection.py
示例18: topic_split_story_count
def topic_split_story_count(topics_id):
if access_public_topic(topics_id):
results = apicache.topic_split_story_counts(TOOL_API_KEY, topics_id, snapshots_id=None, timespans_id=None, foci_id=None,q=None)
elif is_user_logged_in():
results = apicache.topic_split_story_counts(user_mediacloud_key(), topics_id)
else:
return jsonify({'status': 'Error', 'message': 'Invalid attempt'})
return jsonify({'results': results})
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:9,代码来源:attention.py
示例19: _cached_tag_coverage_pct
def _cached_tag_coverage_pct(query, tag_sets_id):
user_mc = user_mediacloud_client()
story_count = source_story_count(user_mediacloud_key(), query)
tagged_story_counts = user_mc.storyTagCount(solr_query=query, tag_sets_id=tag_sets_id)
# sum tagged articles because there are different versions
tagged_sum = sum([tag_info['count'] for tag_info in tagged_story_counts])
# compute coverage ratio (protect against div by zero)
ratio = float(tagged_sum) / float(story_count) if story_count > 0 else 0
return ratio
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:9,代码来源:apicache.py
示例20: remove_sources_from_collection
def remove_sources_from_collection(collection_id):
source_ids_to_remove = request.form['sources[]'].split(',')
source_ids_to_remove = [int(s) for s in source_ids_to_remove]
user_mc = user_admin_mediacloud_client()
# get the sources in the collection first, then remove and add as needed
existing_source_ids = [int(m['media_id']) for m in media_with_tag(user_mediacloud_key(), collection_id)]
source_ids_to_remain = list(set(existing_source_ids) - set(source_ids_to_remove))
media_to_remove = [MediaTag(sid, tags_id=collection_id, action=TAG_ACTION_REMOVE) for sid in source_ids_to_remove]
media_to_remain = [MediaTag(sid, tags_id=collection_id, action=TAG_ACTION_ADD) for sid in
source_ids_to_remain] # do I need to run similar or TAG_ACTION_REMOVE?
current_media = media_to_remove + media_to_remain
if len(current_media) > 0:
results = user_mc.tagMedia(current_media)
apicache.invalidate_collection_source_representation_cache(user_mediacloud_key(), collection_id)
return jsonify(results)
开发者ID:c4fcm,项目名称:MediaMeter-TopicMapper,代码行数:18,代码来源:collectionedit.py
注:本文中的server.auth.user_mediacloud_key函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论