def prepare_empty_post(self): """ Prepare an empty post instance that can be filled with content and eventually published on the blog. """ self.pending_post = wordpress_xmlrpc.WordPressPost() self.pending_post.content = ""
def __convert_post(self, post): newpost = wordpress_xmlrpc.WordPressPost() if post: if 'id' in post: newpost.id = post['id'] if 'title' in post: newpost.title = post['title'] newpost.content = post.get('content', '') newpost.post_status = 'draft' if post.get('status'): newpost.post_status = post['status'] cats = post.get('category') tags = post.get('tag') if cats or tags: newpost.terms_names = {} if cats: newpost.terms_names['category'] = cats if tags: newpost.terms_names['post_tag'] = tags if post.get('comment'): newpost.comment_status = post['comment'] if post.get('date'): newpost.date = post['date'] if post.get('date_modifed'): newpost.date_modified = post['date_modified'] if post.get('slug'): newpost.slug = post['slug'] else: newpost.post_status = 'draft' newpost.comment_status = 'open' newpost.content = '' return newpost
def add_post(self, post, ul_resources=False): rec = wordpress_xmlrpc.WordPressPost() rec.title = extract_title(post._message) rec.content = format_message(post._message) if post._pictures: if ul_resources: post._pictures = [self.upload(f) for f in post._pictures] images = ''.join('<img src="{}" />\n'.format(url) for url in post._pictures) rec.content = images + '<br />\n' + rec.content if post._attachments: if ul_resources: post._attachments = [(name, self.upload(f)) for name, f in post._attachments] attachments = ''.join( '<div><a href="{}">{}</a></div>\n'.format(url, name) for name, url in post._attachments) rec.content += '<br />\n<div>קבצים מצורפים:</div>\n' + attachments rec.date = facebook_timestamp_to_datetime(post._created_time) if post._updated_time != post._created_time: rec.date_modified = facebook_timestamp_to_datetime( post._updated_time) rec.terms_names = {'post_tag': [post._from['name']]} rec.post_status = 'publish' rec.comment_status = 'open' if self._debug: print('posting') post_id = self._client.call(posts.NewPost(rec)) self.add_comments(post_id, post_id, post._comments, ul_resources)
def create_wp_post(post_title, post_body, tag_list, date_scheduled): try: conn = sqlite3.connect(db_path) cur = conn.cursor() cur.execute("SELECT wp_category FROM configuration") config = cur.fetchone() wp_category = config[0] post = wp.WordPressPost() post.title = post_title post.description = post_body post.categories = [wp_category] post.tags = tag_list if date_scheduled: post.date_created = date_scheduled return post except sqlite3.Error, err: if conn: conn.rollback() print "Error when getting configuration: %s" % err.args[0] sys.exit(1)
async def create_post_for_video( video: YtdlPafy) -> xmlrpc.methods.posts.NewPost: post = xmlrpc.WordPressPost() post.title = video.title post.content = ( f"{await make_embed_code(video)}<hr />{process_description(video.description)}" ) post.post_status = "publish" return xmlrpc.methods.posts.NewPost(post)
def handle_post(self, entry): post = wordpress_xmlrpc.WordPressPost() post.title = entry.findall('./subject')[0].text body = entry.findall('./body')[0].text if '{geshi' in body: body = re.sub('{geshi lang=([^ ]+).*?}(.*?){/geshi}', '<pre lang="\\1">\\2</pre>', body, flags=re.DOTALL | re.MULTILINE) post.content = body if '<EXCERPT>' in body: post.excerpt = body[:body.find('<EXCERPT>')] if int(entry.findall('./level_id')[0].text) == 0: post.post_status = 'publish' if entry.findall('./trackback')[0].text: sys.stderr.write("trackback not empty!\n") post.comment_status = 'open' post.date = dateutil.parser.parse(entry.findall('./date')[0].text) post.slug = entry.findall('./permalink')[0].text categories = [] for category in entry.findall('./category'): categories += [category.text] post.terms_names = {'category': categories} # TODO: # tags # comment_mode # self-linki new_post = wordpress_xmlrpc.methods.posts.NewPost(post) post_id = self.client.call(new_post) comments = entry.findall('./comment') for n, comment_node in enumerate(comments, 1): print(">%d/%d" % (n, len(comments))) comment = wordpress_xmlrpc.WordPressComment() comment.content = comment_node.findall('./body')[0].text tmp_date_txt = comment_node.findall('./date')[0].text comment.date_created = dateutil.parser.parse(tmp_date_txt) comment.author = comment_node.findall('./nick')[0].text comment.author_url = comment_node.findall('./nick_url')[0].text try: new_comment = wordpress_xmlrpc.methods.comments.NewComment comment_id = self.client.call(new_comment(post_id, comment)) edit_comment = wordpress_xmlrpc.methods.comments.EditComment self.client.call(edit_comment(comment_id, comment)) except Exception as e: print(repr(e))
def getDefaultPost(self): post = wp.WordPressPost() try: post_attrs = (post.definition.keys()) for k, v in self.config['post_defaults'].items(): if k in post_attrs: setattr(post, k, v) except KeyError: print('No post defaults defined') setattr(post, 'terms_names', {'category': list(), 'post_tag': list()}) return post
def post_draft(title, body): cfg_filename = path('~/.wphelper').expanduser() cfg = configparser.ConfigParser() if not cfg.read(cfg_filename): raise RuntimeError('Did not find configuration file {}'.format(cfg_filename)) site_url = cfg['site']['url'] xmlrpc_url = site_url + '/xmlrpc.php' username = cfg['site']['username'] password = cfg['site']['password'] wp = wordpress_xmlrpc.Client(xmlrpc_url, username, password) post = wordpress_xmlrpc.WordPressPost() post.title = title post.content = body post.post_status = 'draft' post.terms_names = { 'post_tag': ['PyMOTW', 'python'], } wp.call(wordpress_xmlrpc.methods.posts.NewPost(post))
def Post(self): """@Doc:发送帖子""" wp = wordpress_xmlrpc.Client(self.host, self.user, self.pwd) post = wordpress_xmlrpc.WordPressPost() post.title = self.title post.content = self.content post.post_status = 'publish' """ # 栏目ID # post.taxonomy = self.entity # post.terms_names = { # 'post_tag': [self.entity], # # 'category': ['多动症常识', '治疗多动症的医生'] # } """ id = wp.call(NewPost(post)) host = self.host.replace('xmlrpc.php', '') if not id: raise RuntimeError("POST Send failed") else: print '[+] 报告爷 帖子发送成功' + host + str(id) + '.html' print >> okFile, '[+] 报告爷 帖子发送成功' + host + str(id) + '.html'
def __init__(self): self.user = None self.password = None self.url = None self.post = wp_rpc.WordPressPost()
plt.savefig(str(stock[i]) + '.png', bbox_inches='tight', format='png', dpi=200) # Save as STOCK.PNG else: # Print Last Updated Price if Not Recent print('Closing Prices Last Updated: ' + str(f.index[len(f.index) - 1])) quit() # Quit if Prices Aren't Updated wpUser = str( input('Enter WordPress Username: '******'Enter WordPress Password: '******'https://bspt82221685.wordpress.com/xmlrpc.php' # WordPress URL (XMLRPC) wp = wordpress_xmlrpc.Client(wpURL, wpUser, wpPW) # Login to WordPress wpPost = wordpress_xmlrpc.WordPressPost() # Create New Post wpMM = str(datetime.now().strftime('%m')) # MM wpDD = str(datetime.now().strftime('%d')) # DD wpYYYY = str(datetime.now().strftime('%Y')) # YYYY wpPost.title = 'Stock Market Movers: ' + wpMM + '/' + wpDD + '/' + wpYYYY # Add Title htmlIMG = [] for i in range(len(stock)): # Upload Charts to WordPress imgName = 'https://bspt82221685.files.wordpress.com/' + wpYYYY + '/' + wpMM + '/' + str( stock[i]).lower() + '.png' htmlIMG.append('<figure class="wp-block-image"><a href="' + imgName + '"><img src="' + imgName + '" alt=""/></a></figure>') # Add HTML Tags to Figure data = { 'name': str(stock[i]).lower() + '.png', 'type': 'image/png',