def create_post(self, title, content, post_format='image', tag=None, category=None, thumnnail_path=None): post = WordPressPost() post.title = title post.content = content post.comment_status = 'open' post.post_format = post_format # image,video,0 post.post_status = 'publish' # 文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布 post.terms_names = { 'post_tag': tag #['test', 'beauty'], 文章所属标签,没有则自动创建 , 'category': category #['校园美女'] 文章所属分类,没有则自动创建 } if thumnnail_path is None: post.thumbnail = None elif thumnnail_path.startswith('http'): post.thumbnail = self.add_external_image(thumnnail_path) else: post.thumbnail = self._find_media(thumnnail_path) # 缩略图的id try: self.wp.call(posts.NewPost(post)) except Exception as e: print(e)
def createMP3Post(self, presenter, title, reference, date_str, media_url, verbose=False): if verbose: print 'createMP3Post starting' post = WordPressPost() titleTemplate = u"""Podcast : {0} : {1} - {2}""" title = title.encode('ascii','ignore') post.title = titleTemplate.format(date_str, presenter, title) template = u"""[audio "{4}" ]<p>{0} : {1} - {2} - {3}</p>""" post.content = template.format(date_str, presenter, title, reference, media_url) post.post_status = 'publish' # set the category so this Post is inserted into our 'podcast' feed post.terms_names = {'category': [self.feed_category,]} post.post_format = 'Link' retval = None try: print ' post = ', post print 'post.content =', post.content retVal = self.client.call(posts.NewPost(post)) except Exception as inst: print 'createMP3Post: posts.NewPost() failed', inst else: if verbose: print 'createMP3Post complete' return retVal
def func_Create_WP_Post(atitle, acontent, category): wp = Client(WPPATH, WPUSER, WPPASS) my_category = category post = WordPressPost() post.title = atitle post.content = acontent post.post_format = "video" post.terms_names = {'category':[my_category]} print(category) print("---") my_posts = [] #my_posts = set() my_increment = 20 my_offset = 0 while True: wp_obj_posts = wp.call(posts.GetPosts({'number': my_increment, "offset": my_offset})) if len(wp_obj_posts) == 0: break for apost in wp_obj_posts: apost = apost.content apost = apost.split("embed/",1)[1] #my_posts.add(apost) my_posts.append(apost) #try: # print(apost.title) #except UnicodeEncodeError: # print("'ascii' codec can't encode character.") my_offset += my_increment #print(wp_obj_posts) #print("---") print(my_posts) print("---") post_id = post.content.split("embed/",1)[1] print(post_id) #my_posts = sorted(my_posts) if post_id in my_posts: print("Dublicate post!!!\n") print("---") else: print("Posted!\n") print("---") post.id = wp.call(posts.NewPost(post)) post.post_status = 'publish' wp.call(posts.EditPost(post.id, post))
def createPost(self, title, content, category, post_format='Standard'): post = WordPressPost() post.title = title.encode('ascii', 'ignore') post.content = content.encode('ascii', 'ignore') post.post_status = 'publish' # set the category so this Post is inserted into the correct feed post.terms_names = { 'category': [ category, ] } post.post_format = post_format return self.client.call(posts.NewPost(post))
def wordpress_post(config): print("Connecting to: " + config.wordpress['xmlrpc']) wp = Client(config.wordpress['xmlrpc'], config.wordpress['username'], config.wordpress['password']) if config.attach_header: print("Uploading header image...") # Upload header image data = { 'name': os.path.basename(config.png_header_file), 'type': 'image/png', } # Read the image and let the XMLRPC library encode it to base64 with open(config.png_header_file, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read()) response = wp.call(media.UploadFile(data)) attachment_id = response['id'] print("Posting blog...") post = WordPressPost() post.title = config.wordpress['title'] post.content = config.wordpress['content'] post.post_format = config.wordpress['post_format'] post.post_status = config.wordpress['post_status'] post.comment_status = config.wordpress['comment_status'] if config.attach_header: post.thumbnail = attachment_id post.terms_names = { 'post_tag': [config.wordpress['tags']], 'category': [config.wordpress['category']] } post.id = wp.call(NewPost(post)) if config.wordpress['podcast_plugin'] == 'Powerpress': get_audio_size_and_duration(config)
def wordpress_post(config): print("Connecting to: " + config.wordpress['xmlrpc']) wp = Client(config.wordpress['xmlrpc'], config.wordpress['username'], config.wordpress['password']) if config.attach_header: print("Uploading header image...") # Upload header image data = { 'name': os.path.basename(config.png_header_file), 'type': 'image/png', } # Read the image and let the XMLRPC library encode it to base64 with open(config.png_header_file, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read()) response = wp.call(media.UploadFile(data)) attachment_id = response['id'] print("Posting blog...") post = WordPressPost() post.title = config.wordpress['title'] post.content = config.wordpress['content'] post.post_format = config.wordpress['post_format'] post.post_status = config.wordpress['post_status'] post.comment_status = config.wordpress['comment_status'] if config.attach_header: post.thumbnail = attachment_id # FIXME: Make sure tags and category are defined. Don't assume they are. post.terms_names = { 'post_tag': [config.wordpress['tags']], 'category': [config.wordpress['category']] } url = config.wordpress['uploads_url'].format(config.season, config.episode, config.mp3_file) if config.wordpress['podcast_plugin'] == 'Powerpress': config = get_audio_size_and_duration(config) enclosureData = { 'duration': config.mp3['duration'], 'size': config.mp3['size'], ### Below items are best left undefined unless we really ### want to force their settings per upload. # 'embed': True, # 'keywords': '', # 'subtitle': '', # 'summary': '', # 'gp_desc': '', # 'gp_explicit': False, # 'gp_block': '', # 'author': '', # 'no_player': False, # 'no_links': False, # 'explicit': False, # 'cc': '', # 'order': 0, # 'always': '', # 'block': '', # 'image': '', # 'ishd': False, # Is an HD Video # 'height': 0, # Video Height # 'width': 0, # Video Width # 'webm_src': '', # 'feed_title': '', } post.custom_fields = [] post.custom_fields.append({ 'key': 'enclosure', 'value': "{}\n{}\n{}\n{}".format(url, config.mp3['size'], config.tags['podcast_type'] or 'episodic', dumps(enclosureData).decode('ascii')), }) post.id = wp.call(NewPost(post))