python csv wordpress xmlrpc_使用python-wordpress-xmlrpc操作wordpress

用到的库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(‘http://127.0.0.1/xmlrpc.php‘, ‘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(‘http://127.0.0.1/xmlrpc.php‘, ‘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))

原文:http://my.oschina.net/ranvane/blog/390684

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值