用到的库python-wordpress-xmlrpc
url :
新建tag或者category:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from wordpress_xmlrpc import Client, WordPressPost, WordPressTerm
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.methods import taxonomies
import csv
wp = Client('外链网址已屏蔽', 'root', '123456')
tag = WordPressTerm()
tag.taxonomy = 'category'#这里为category的话插入的是category,为post_tag的话插入的是tag
tag.name = 'My New Tag'
tag.id = wp.call(taxonomies.NewTerm(tag))
发表博文:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from wordpress_xmlrpc import Client, WordPressPost, WordPressTerm
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.methods import taxonomies
import csv
wp = Client('外链网址已屏蔽', 'root', '123456')
"""
发表博文
"""
post = WordPressPost()
post.title = 'My new title'
post.content = 'This is the body of my new post.'
post.post_status = 'publish'
post.terms_names = {
'post_tag': ['test', 'firstpost'],
'category': ['Introductions', 'Tests']
}
wp.call(NewPost(post))
新建带有父category/tag的子category/tag
parent_cat = client.call(taxonomies.GetTerm('category', 3))
child_cat = WordPressTerm()
child_cat.taxonomy = 'category'#这里为category的话插入的是category,为post_tag的话插入的是tag
child_cat.parent = parent_cat.id
child_cat.name = 'My Child Category'
child_cat.id = client.call(taxonomies.NewTerm(child_cat))