def _update_term(self): q = self.args.query term = None query = self.get_term_query() typ = query[0] if q and len(q) > 1: term = self.get_terms_from_wp(query, force=True) if not term: slog.error('The term %s is not existend.'%str(q)) return term = self.wpcall(GetTerm(typ, term.id)) if term: term.slug = q[0] term.name = q[1] if len(q)>2: term.description = q[2] # post_get can not support parent. if term.taxonomy == 'post_tag': term.parent = None issucc = self.wpcall(EditTerm(term.id, term)) if issucc: self.conf.save_term(term, typ) self.conf.save_to_file() slog.info('The term %s(%s) has saved.'%(term.slug, term.id)) else: slog.info('The term %s(%s) saves unsuccessfully.'%(term.slug, term.id)) else: slog.info('Can not get term "%s".'%typ) else: term = self.get_terms_from_wp(query, force=True) if term: slog.info('Update terms done.') else: slog.warning('No terms.')
def _show_term(self): query = self.get_term_query() info = str(query) terms = self.get_terms_from_wp(query) if terms: self.print_results(terms) else: slog.warning('No term %s!'%info)
def _show_mediaitem(self): if not self.args.query or len(self.args.query) == 0: slog.error('Please provide a attachment_id!') return result = self.wpcall(GetMediaItem(self.args.query[0])) if result: self.print_result(result) else: slog.warning('No results for showing.')
def _update_articles(self): postids = self.get_postid(as_list=True) if not postids: slog.warning('Please provide a post id!') return # Update all taxonomy before create a new article. self.get_terms_from_wp(['category']) self.get_terms_from_wp(['post_tag']) for postid in postids: self._update_an_article(postid)
def _show_medialib(self): field = {} field['number'] = self.args.number extra = self.get_dict_from_query(self.args.query) if extra: for k,v in extra.items(): field[k] = v print(field) results = self.wpcall(GetMediaLibrary(field)) if results: self.print_results(results) else: slog.warning('No results for showing.')
def _show_post(self): field = {} field['number'] = self.args.number field['orderby'] = self.args.orderby field['order'] = self.args.order method = None if self.args.query: method = GetPost(_get_postid()) else: method = GetPosts(field) results = self.wpcall(method) if results: self.print_results(results) else: slog.warning('No results for showing.')
def _show_page(self): field = {'post_type':'page'} field['number'] = self.args.number field['orderby'] = self.args.orderby field['order'] = self.args.order method = None if self.args.query: method = GetPost(_get_postid(), result_class=WordPressPage) else: method = GetPosts(field, result_class=WordPressPage) results = self.wpcall(method) if results: self.print_results(results) else: slog.warning('No results for showing.')
def _update_an_article(self, postid): afile, aname = self.conf.get_article(postid, self.args.type) html, meta, txt, medias = self._get_and_update_article_content(afile) if not html: return resultclass = WordPressPost if self.args.type == 'page': postid = meta.postid resultclass = WordPressPage post = self.wpcall(GetPost(postid, result_class=resultclass)) if not post: slog.warning('No post "%s"!' % postid) return slog.info('Old article:') self.print_results(post) post.title = meta.title post.user = meta.author post.slug = meta.nicename post.date = meta.date post.content = html post.post_status = meta.poststatus if meta.modified: post.date_modified = meta.modified terms = self.get_terms_from_meta(meta.category, meta.tags) if terms: post.terms = terms elif self.args.type == 'post': slog.warning('Please provide some terms.') return succ = self.wpcall(EditPost(postid, post)) if succ == None: return if succ: slog.info('Update %s successfully!' % postid) else: slog.info('Update %s fail!' % postid)
def _update_an_article(self, postid): afile, aname = self.conf.get_article(postid, self.args.type) html, meta, txt, medias = self._get_and_update_article_content(afile) if not html: return resultclass = WordPressPost if self.args.type == 'page': postid = meta.postid resultclass = WordPressPage post = self.wpcall(GetPost(postid, result_class=resultclass)) if not post: slog.warning('No post "%s"!'%postid) return slog.info('Old article:') self.print_results(post) post.title = meta.title post.user = meta.author post.slug = meta.nicename post.date = meta.date post.content = html post.post_status = meta.poststatus if meta.modified: post.date_modified = meta.modified terms = self.get_terms_from_meta(meta.category, meta.tags) if terms: post.terms = terms elif self.args.type == 'post': slog.warning('Please provide some terms.') return succ = self.wpcall(EditPost(postid, post)) if succ == None: return if succ: slog.info('Update %s successfully!'%postid) else: slog.info('Update %s fail!'%postid)
def _update_term(self): q = self.args.query term = None query = self.get_term_query() typ = query[0] if q and len(q) > 1: term = self.get_terms_from_wp(query, force=True) if not term: slog.error('The term %s is not existend.' % str(q)) return term = self.wpcall(GetTerm(typ, term.id)) if term: term.slug = q[0] term.name = q[1] if len(q) > 2: term.description = q[2] # post_get can not support parent. if term.taxonomy == 'post_tag': term.parent = None issucc = self.wpcall(EditTerm(term.id, term)) if issucc: self.conf.save_term(term, typ) self.conf.save_to_file() slog.info('The term %s(%s) has saved.' % (term.slug, term.id)) else: slog.info('The term %s(%s) saves unsuccessfully.' % (term.slug, term.id)) else: slog.info('Can not get term "%s".' % typ) else: term = self.get_terms_from_wp(query, force=True) if term: slog.info('Update terms done.') else: slog.warning('No terms.')
def _update_a_draft(self): postid = self.get_postid() if not postid: slog.warning('Please provide a post id!') return afile, aname = self.conf.get_draft(postid) html, meta, txt, medias = self._get_and_update_article_content(afile) if not html: return if meta.poststatus == 'draft': slog.warning('The post status of draft "%s" is "draft", ' 'please modify it to "publish".' % postid) return # Update all taxonomy before create a new article. self.get_terms_from_wp(['category']) self.get_terms_from_wp(['post_tag']) if meta.posttype == 'page': post = WordPressPage() else: post = WordPressPost() post.content = html post.title = meta.title post.slug = meta.nicename post.date = meta.date post.user = meta.author post.date_modified = meta.modified post.post_status = meta.poststatus post.terms = self.get_terms_from_meta(meta.category, meta.tags) if not post.terms: slog.warning('Please provide some terms.') return postid = self.wpcall(NewPost(post)) if postid: write_by_templ(afile, afile, { 'POSTID': postid, 'SLUG': postid }, True) else: return newfile, newname = None, None if meta.posttype == 'page': newfile, newname = self.conf.get_article(post.nicename, meta.posttype) else: newfile, newname = self.conf.get_article(postid, meta.posttype) slog.info('Move "%s" to "%s".' % (afile, newfile)) shutil.move(afile, newfile)
def _update_a_draft(self): postid = self.get_postid() if not postid: slog.warning('Please provide a post id!') return afile, aname = self.conf.get_draft(postid) html, meta, txt, medias = self._get_and_update_article_content(afile) if not html: return if meta.poststatus == 'draft': slog.warning('The post status of draft "%s" is "draft", ' 'please modify it to "publish".'%postid) return # Update all taxonomy before create a new article. self.get_terms_from_wp(['category']) self.get_terms_from_wp(['post_tag']) if meta.posttype == 'page': post = WordPressPage() else: post = WordPressPost() post.terms = self.get_terms_from_meta(meta.category, meta.tags) if not post.terms: slog.warning('Please provide some terms.') return post.content= html post.title = meta.title post.slug = meta.nicename post.date = meta.date post.user = meta.author post.date_modified = meta.modified post.post_status = meta.poststatus postid = self.wpcall(NewPost(post)) if postid: write_by_templ(afile, afile, {'POSTID':postid, 'SLUG':postid}, True) else: return newfile, newname = None, None if meta.posttype == 'page': newfile, newname = self.conf.get_article(meta.nicename, meta.posttype) else: newfile, newname = self.conf.get_article(postid, meta.posttype) slog.info('Move "%s" to "%s".'%(afile, newfile)) shutil.move(afile, newfile)
def _show_tax(self): results = self.wpcall(GetTaxonomies()) if results: self.print_results(results) else: slog.warning('No results for showing.')
def _show_options(self): results = self.wpcall(GetOptions([])) if results: self.print_results(results) else: slog.warning('No results for showing.')