def _create_wp_post(song, content): # Create the NewPost object - see docs at # http://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/wordpress.html # We're missing some fields but ehhhh who knows if they even exist anymore post = WordPressPost() post.title = str(song) post.content = content post.comment_status = 'open' post.ping_status = 'closed' post.post_status = 'publish' post.post_type = 'post' post.excerpt = song.tagline post.date = datetime.now(tz=timezone.utc) post.date_modified = datetime.now(tz=timezone.utc) return NewPost(post)
def publish(pic, title, content): ''' publish a post and set to open to comment and ping(trackback) ''' attachment = upload(pic) wp_client = Client(rpc_service_url, user, password) post = WordPressPost() post.title = title post.content = "%s\n\n<a href='%s'><img class='alignnone size-full wp-image-%s' alt='%s' src='%s' /></a>" % (content, attachment['url'], attachment['id'], attachment['file'], attachment['url']) #post.tags='test, test2' #post.categories=['pet','picture'] post.thumbnail = attachment['id'] #change status to publish post.id = wp_client.call(posts.NewPost(post)) post.post_status = 'publish' post.comment_status = 'open' post.ping_status = 'open' post.user = account_ids[r.randint(0, len(account_ids)-1)] wp_client.call(posts.EditPost(post.id, post)) return post.id
# substitute picture placeholders in content with WP loaded URL if response['url'] is not None: parsed_url = urlparse.urlparse(response['url']) html_img='<a href=' + response['url'] + ' target=_blank><img class=aligncenter src=' + response['url'] + ' /></a>' content = content.replace('[IMG' + str(filecount) + ']', html_img) else: print "DBG File '" + filename +"' cannot be found." sys.exit(1) # assemble post object (as draft first) new_post = WordPressPost() new_post.status = 'draft' new_post.title = title new_post.content = content new_post.comment_status = 'open' new_post.ping_status = 'open' if post_date is not None and len(post_date.strip()) > 0: #new_post.date = dateutil.parser.parse(post_date + " " + datetime.now(tzlocal()).tzname()) new_post.date = dateutil.parser.parse(post_date) # categorise post if categories is not None and len(categories.strip()) > 0: for category in categories.split(','): category_objects = wordpress.call(taxonomies.GetTerms('category', {'search': category, 'orderby': 'count', 'number': 1})) if category_objects != None: for category_object in category_objects: new_post.terms.append(category_object) # dump out post object #pp = pprint.PrettyPrinter(indent=1,width=80,depth=3)