溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

metaWeblog同步博客遇到的問題怎么解決

發(fā)布時間:2022-01-05 14:32:37 來源:億速云 閱讀:115 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“metaWeblog同步博客遇到的問題怎么解決”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

技術上使用metaWeblog就可以實現(xiàn)上述目的,選用python的xmlrpclib可以方便的進行xmlrpc操作。做一個控制臺的小程序足夠了我使用了。

然后開始技術實驗,發(fā)現(xiàn):

  1. wordpress支持metaWeblog很好,可以實現(xiàn)所有的功能。從wordpress可以通過metaWeblog.getRecentPosts函數(shù)得到所有的文章。

  2. cnblogs也支持metaWeblog,也支持的很好。cnblogs也支持我的語法高亮。但遺憾的是:第一:metaWeblog.getRecentPosts函數(shù)最多能夠返回100個文章。而我的cnblogs目前有230篇文章,很顯然,cnblogs限制了文章數(shù)量;第二:metaWeblog.newPost函數(shù)即便Post結構中有dateCreated,但cnblogs的主界面中依然按照當前時間計算,造成文章時間對不上號,順序混亂。

  3. csdn就是個垃圾,metaWeblog表面上支持,暗地里出問題。metaWeblog.getRecentPosts,metaWeblog.editPost都無法用,提示User not exist。僅有metaWeblog.newPost可以用,但csdn的blog的語法高亮無法用,頁面很難看。

所以,想實現(xiàn)我的目的通過metaWeblog看來是沒希望了。除非cnblogs調(diào)整文章數(shù)量限制,csdn希望從垃圾變成戰(zhàn)斗機了。

附我寫的一個測試代碼,不完善,僅作為參考:

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同步博客遇到的問題怎么解決”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI