def _create_metadata(self, status, excerpt, tags, categories, post_name=None): """Create post metadata.""" other_meta = {'wp-status': status} if excerpt is not None: other_meta['excerpt'] = excerpt if self.export_categories_as_categories: cats = [] for text in categories: if text in self._category_paths: cats.append(self._category_paths[text]) else: cats.append(utils.join_hierarchical_category_path([text])) other_meta['categories'] = ','.join(cats) if len(cats) > 0: other_meta['category'] = cats[0] if len(cats) > 1: LOGGER.warn( ('Post "{0}" has more than one category! ' + 'Will only use the first one.').format(post_name)) tags_cats = tags else: tags_cats = tags + categories return tags_cats, other_meta
def _prepare(self, channel): """Prepare context and category hierarchy.""" self.context = self.populate_context(channel) self.base_dir = urlparse(self.context['BASE_URL']).path if self.export_categories_as_categories: wordpress_namespace = channel.nsmap['wp'] cat_map = dict() for cat in channel.findall( '{{{0}}}category'.format(wordpress_namespace)): # cat_id = get_text_tag(cat, '{{{0}}}term_id'.format(wordpress_namespace), None) cat_slug = get_text_tag( cat, '{{{0}}}category_nicename'.format(wordpress_namespace), None) cat_parent_slug = get_text_tag( cat, '{{{0}}}category_parent'.format(wordpress_namespace), None) cat_name = get_text_tag( cat, '{{{0}}}cat_name'.format(wordpress_namespace), None) cat_path = [cat_name] if cat_parent_slug in cat_map: cat_path = cat_map[cat_parent_slug] + cat_path cat_map[cat_slug] = cat_path self._category_paths = dict() for cat, path in cat_map.items(): self._category_paths[ cat] = utils.join_hierarchical_category_path(path)
def _prepare(self, channel): self.context = self.populate_context(channel) self.base_dir = urlparse(self.context['BASE_URL']).path if self.export_categories_as_categories: wordpress_namespace = channel.nsmap['wp'] cat_map = dict() for cat in channel.findall('{{{0}}}category'.format(wordpress_namespace)): # cat_id = get_text_tag(cat, '{{{0}}}term_id'.format(wordpress_namespace), None) cat_slug = get_text_tag(cat, '{{{0}}}category_nicename'.format(wordpress_namespace), None) cat_parent_slug = get_text_tag(cat, '{{{0}}}category_parent'.format(wordpress_namespace), None) cat_name = get_text_tag(cat, '{{{0}}}cat_name'.format(wordpress_namespace), None) cat_path = [cat_name] if cat_parent_slug in cat_map: cat_path = cat_map[cat_parent_slug] + cat_path cat_map[cat_slug] = cat_path self._category_paths = dict() for cat, path in cat_map.items(): self._category_paths[cat] = utils.join_hierarchical_category_path(path)
def _create_metadata(self, status, excerpt, tags, categories, post_name=None): other_meta = {'wp-status': status} if excerpt is not None: other_meta['excerpt'] = excerpt if self.export_categories_as_categories: cats = [] for text in categories: if text in self._category_paths: cats.append(self._category_paths[text]) else: cats.append(utils.join_hierarchical_category_path([text])) other_meta['categories'] = ','.join(cats) if len(cats) > 0: other_meta['category'] = cats[0] if len(cats) > 1: LOGGER.warn(('Post "{0}" has more than one category! ' + 'Will only use the first one.').format(post_name)) tags_cats = tags else: tags_cats = tags + categories return tags_cats, other_meta
def recombine_classification_from_hierarchy(self, hierarchy): """Given a list of parts in the hierarchy, return the classification string.""" return utils.join_hierarchical_category_path(hierarchy)