def _tag_set_with_collections(tag_sets_id, show_only_public_collections): # TODO use which mc or user_mc here tag_set = mc.tagSet(tag_sets_id) # page through tags more_tags = True all_tags = [] last_tags_id = 0 while more_tags: tags = mc.tagList(tag_sets_id=tag_set['tag_sets_id'], last_tags_id=last_tags_id, rows=100, public_only=show_only_public_collections) all_tags = all_tags + tags if len(tags) > 0: last_tags_id = tags[-1]['tags_id'] more_tags = len(tags) != 0 collection_list = [ t for t in all_tags if t['show_on_media'] is 1 ] # double check the show_on_media because that controls public or not collection_list = sorted(collection_list, key=itemgetter('label')) return { 'name': tag_set['label'], 'description': tag_set['description'], 'collections': collection_list }
def write_tags_in_set_to_json(tag_sets_id_list, only_public_tags=True, filepath=None): logger.info(u"Starting to generate a list of all the collections in tag sets: {}".format(tag_sets_id_list)) for tag_sets_id in tag_sets_id_list: filename = "tags_in_{}.json".format(tag_sets_id) tag_set = mc.tagSet(tag_sets_id) logger.info(u" {}".format(tag_set['label'])) tags_list = apicache.tags_in_tag_set(TOOL_API_KEY, tag_sets_id, only_public_tags) output_filepath = os.path.join(data_dir, filename) if filepath is None else filepath with open(output_filepath, 'wb') as f: json.dump(tags_list, codecs.getwriter('utf-8')(f), ensure_ascii=False) logger.info(u" wrote {} collections to {}".format(len(tags_list['tags']), filename)) logger.info(u"Done")
def write_tags_in_set_to_json(tag_sets_id_list, only_public_tags=True, filepath=None): logger.info("Starting to generate a list of all the collections in tag sets: {}".format(tag_sets_id_list)) for tag_sets_id in tag_sets_id_list: filename = "tags_in_{}.json".format(tag_sets_id) tag_set = mc.tagSet(tag_sets_id) logger.info(" {}".format(tag_set['label'])) tags_list = apicache.tags_in_tag_set(TOOL_API_KEY, tag_sets_id, only_public_tags) output_filepath = os.path.join(data_dir, filename) if filepath is None else filepath with open(output_filepath, 'wb') as f: json.dump(tags_list, codecs.getwriter('utf-8')(f), ensure_ascii=False) logger.info(" wrote {} collections to {}".format(len(tags_list['tags']), filename)) logger.info("Done")
def _tag_set_with_collections(tag_sets_id, show_only_public_collections): # TODO use which mc or user_mc here tag_set = mc.tagSet(tag_sets_id) # page through tags more_tags = True all_tags = [] last_tags_id = 0 while more_tags: tags = mc.tagList(tag_sets_id=tag_set['tag_sets_id'], last_tags_id=last_tags_id, rows=100, public_only=show_only_public_collections) all_tags = all_tags + tags if len(tags) > 0: last_tags_id = tags[-1]['tags_id'] more_tags = len(tags) != 0 # double check the show_on_media because that controls public or not collection_list = [t for t in all_tags if t['show_on_media'] is 1] collection_list = sorted(collection_list, key=itemgetter('label')) return { 'name': tag_set['label'], 'description': tag_set['description'], 'collections': collection_list }