thank you for using python_Using Python+MetaWeblog to manage your blog

See RFC: http://www.xmlrpc.com/MetaWeblogApi for reference on MetaWeblog API.

One user on a site may have multiple blogs, one blog contain multiple posts, one post contain at least title and description attributes, as follwing figure shows.

The most import 3 entry points of metaWeblog are:

metaWeblog.newPost (blogid, username, password, struct, publish) returns string

metaWeblog.editPost (postid, username, password, struct, publish) returns true

metaWeblog.getPost (postid, username, password) returns struct

The content of one blog are represented as struct.

you can upload the blog to site without publish to others, so comes the publish parameter to newPost and editPost, this bool value control whether the blog should be published.

There are also methods to list posts get/delete a post which won't be listed here. Final piece of the API is handle mediaObject in Html.

MetaWeblog.newMediaObject (blogid, username, passwd, file) return URL of uploaded file

For these who are curisoty, following Python code demo how to wrap newPost methods and how to use it.

import xmlrpclib

class MetaWeblog:

'''works with www.cnblogs.com atleast'''

def __init__(self, serviceUrl, appKey, usr, passwd):

self.serviceUrl, self.appKey, self.usr, self.passwd = serviceUrl, appKey, usr, passwd

self.server = xmlrpclib.ServerProxy(self.serviceUrl)

def newPost(self, title='Title used for test', description='this is a test post.', category='no category', publish=True, blogid='', **kw):

return self.server.MetaWeblog.newPost(blogid, self.usr, self.passwd, dict(kw, title=title, description=description, category=category), publish)

.....

serviceUrl, appKey = 'http://www.cnblogs.com/ans42/services/MetaWeblog.aspx', 'ans42'

usr, passwd = 'ans42', 'xxxxxx'

blog = MetaWeblog(serviceUrl, appKey, usr, passwd)

print blog.newPost('Title', 'content')

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值