温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

metaWeblog同步博客遇到的问题怎么解决

发布时间:2022-01-05 14:32:37 来源:亿速云 阅读:107 作者:iii 栏目:大数据

本篇内容介绍了“metaWeblog同步博客遇到的问题怎么解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

技术上使用metaWeblog就可以实现上述目的,选用python的xmlrpclib可以方便的进行xmlrpc操作。做一个控制台的小程序足够了我使用了。

然后开始技术实验,发现:

  1. wordpress支持metaWeblog很好,可以实现所有的功能。从wordpress可以通过metaWeblog.getRecentPosts函数得到所有的文章。

  2. cnblogs也支持metaWeblog,也支持的很好。cnblogs也支持我的语法高亮。但遗憾的是:第一:metaWeblog.getRecentPosts函数最多能够返回100个文章。而我的cnblogs目前有230篇文章,很显然,cnblogs限制了文章数量;第二:metaWeblog.newPost函数即便Post结构中有dateCreated,但cnblogs的主界面中依然按照当前时间计算,造成文章时间对不上号,顺序混乱。

  3. csdn就是个垃圾,metaWeblog表面上支持,暗地里出问题。metaWeblog.getRecentPosts,metaWeblog.editPost都无法用,提示User not exist。仅有metaWeblog.newPost可以用,但csdn的blog的语法高亮无法用,页面很难看。

所以,想实现我的目的通过metaWeblog看来是没希望了。除非cnblogs调整文章数量限制,csdn希望从垃圾变成战斗机了。

附我写的一个测试代码,不完善,仅作为参考:

import xmlrpclib

class Metablog:
    def __init__(self, url, username, password):
        self.username=username
        self.password=password
        self.url=url
        self.server=xmlrpclib.ServerProxy(url)
        self.posts=None

    def getAllPosts(self):
        print "Getting all posts from "+self.url
        self.posts=self.server.metaWeblog.getRecentPosts('', self.username, self.password, 9999999)
        print "found "+ str(len(self.posts)) +" posts"
        return self.posts;

    def getAllPostTitle(self):
        if self.posts==None:
            self.getAllPosts()

        ret=dict()
        for post in self.posts:
            ret[post["postid"]]=post["title"]

        return ret

    def getPost(self, id):
        for post in self.posts:
            if post["postid"]==id:
                return post

        return None

    def newPost(self, post):
        self.server.metaWeblog.newPost('', self.username, self.password, post, True)

    def editPost(self,postid, post):
        self.server.metaWeblog.editPost(postid, self.username, self.password, post, True)

    def delPost(self, postid):
        self.server.metaWeblog.deletePost('',postid, self.username, self.password, True)

def syncBlog(b1, b2):
    b1Titles=b1.getAllPostTitle()
    b2Titles=b2.getAllPostTitle()
    for key1,value1 in b1Titles.iteritems():
        print "Blog1 title: "+value1
        for key2,value2 in b2Titles.iteritems():
            print "tBlog2 title: "+value2
            if value1==value2:
                print "Syncing, blog 2 postid="+key2
                b2.editPost(keys2, b1.getPost(key1))
                break

        print "Blog2 has no article equal to title :"+value1
        print "Add new "
        b2.newPost(b1.getPost(key1))

    print "Done sync"


wpBlog=Metablog("主站地址", "用户名", "密码")
cnBlog=Metablog("从站地址", "用户名", "密码")
syncBlog(wpBlog, cnBlog)

“metaWeblog同步博客遇到的问题怎么解决”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI