使用gdatapython客户端在blogger上批量发布

使用gdatapython客户端在blogger上批量发布,python,batch-processing,blogger,gdata-python-client,Python,Batch Processing,Blogger,Gdata Python Client,我正试图将我所有的Livejournal帖子复制到blogger.com上的新博客上。我通过使用附带的稍微修改过的来实现这一点。我有一个json文件,其中包含从Livejournal导入的所有帖子。问题是blogger.com每天发布新的博客条目有一个上限——50条,所以你们可以想象,我的1300多条帖子将在一个月内被复制,因为我无法在50次导入后以编程方式输入captcha 我最近了解到gdata中也有批处理操作模式,但我不知道如何使用它。谷歌搜索并没有真正起到帮助作用 如有任何建议或帮助,将

我正试图将我所有的Livejournal帖子复制到blogger.com上的新博客上。我通过使用附带的稍微修改过的来实现这一点。我有一个json文件,其中包含从Livejournal导入的所有帖子。问题是blogger.com每天发布新的博客条目有一个上限——50条,所以你们可以想象,我的1300多条帖子将在一个月内被复制,因为我无法在50次导入后以编程方式输入captcha

我最近了解到gdata中也有批处理操作模式,但我不知道如何使用它。谷歌搜索并没有真正起到帮助作用

如有任何建议或帮助,将不胜感激

谢谢

更新 以防万一,我使用以下代码

#!/usr/local/bin/python
import json
import requests

from gdata import service
import gdata
import atom
import getopt
import sys

from datetime import datetime as dt
from datetime import timedelta as td
from datetime import tzinfo as tz

import time

allEntries = json.load(open("todays_copy.json", "r"))

class TZ(tz):
    def utcoffset(self, dt): return td(hours=-6)

class BloggerExample:
    def __init__(self, email, password):
        # Authenticate using ClientLogin.
        self.service = service.GDataService(email, password)
        self.service.source = "Blogger_Python_Sample-1.0"
        self.service.service = "blogger"
        self.service.server = "www.blogger.com"
        self.service.ProgrammaticLogin()

        # Get the blog ID for the first blog.
        feed = self.service.Get("/feeds/default/blogs")
        self_link = feed.entry[0].GetSelfLink()
        if self_link:
            self.blog_id = self_link.href.split("/")[-1]

    def CreatePost(self, title, content, author_name, label, time):
        LABEL_SCHEME = "http://www.blogger.com/atom/ns#"
        # Create the entry to insert.
        entry = gdata.GDataEntry()
        entry.author.append(atom.Author(atom.Name(text=author_name)))
        entry.title = atom.Title(title_type="xhtml", text=title)
        entry.content = atom.Content(content_type="html", text=content)
        entry.published = atom.Published(time)
        entry.category.append(atom.Category(scheme=LABEL_SCHEME, term=label))

        # Ask the service to insert the new entry.
        return self.service.Post(entry, 
            "/feeds/" + self.blog_id + "/posts/default")

    def run(self, data):
        for year in allEntries:
            for month in year["yearlydata"]:
                for day in month["monthlydata"]:
                    for entry in day["daylydata"]:
                        # print year["year"], month["month"], day["day"], entry["title"].encode("utf-8")
                        atime = dt.strptime(entry["time"], "%I:%M %p")
                        hr = atime.hour
                        mn = atime.minute
                        ptime = dt(year["year"], int(month["month"]), int(day["day"]), hr, mn, 0, tzinfo=TZ()).isoformat("T")
                        public_post = self.CreatePost(entry["title"],
                            entry["content"],
                            "My name",
                            ",".join(entry["tags"]),
                            ptime)
                        print "%s, %s - published, Waiting 30 minutes" % (ptime, entry["title"].encode("utf-8"))
                        time.sleep(30*60)


def main(data):
    email = "my@email.com"
    password = "MyPassW0rd"

    sample = BloggerExample(email, password)
    sample.run(data)

if __name__ == "__main__":
    main(allEntries)

我建议改用谷歌博客转换器()

要开始,你必须经历

-设置Google GData API的步骤 -使用博客转换器的步骤

完成所有设置后,必须运行以下命令(即LiveJournal用户名和密码)


另外,我知道这不是你问题的答案,但因为这个答案的目的与你的问题相同(一天导入50多个帖子),所以我分享了它。我对Python或GDataAPI不太了解,我设置了环境并按照以下步骤回答了这个问题(我可以用它将文章从LiveJournal导入Blogger)。

你能绕过这个问题,通过Python独立脚本手动将每个记录从一个数据库写到另一个数据库吗?不熟悉livejournal或blogger,但我不得不批量发布大量帖子,因此我很有兴趣提供帮助。@Joaq2Remember对不起,我没有真正了解,请澄清一下好吗?谢谢。可能会建立两个到两个数据库的连接;livejournal和blogger。从live journal中选择,然后将副本写入blogger,或者建立blogger db连接,并通过解析Json写入。@Joaq2Remember我希望我可以这样做,但blogger只提供REST API,因此我无法直接访问他们的数据库。所以,您的问题是他们的API post请求受到了严格限制?除了API之外,还有其他发布项目吗?我可能会建议使用机器人通过CMS发布这些帖子,或者尝试与blogger的某个人联系,看看他们是否能帮助你。哦,伙计,这看起来很有希望。我马上测试一下。谢谢和+1。一旦我测试正确,我会将它标记为解决方案。我还发现了不同的文档。构建请求提要似乎有所不同,但这是一些相关文档。为了构建提要,它使用GDatafeed。让我知道你的想法think@Kaster赏金很快就要结束了。。。让我知道你进展如何,以便它可以被授予/不授予,或者不管是什么情况:)@JonClements不幸的是,到目前为止,我无法使它工作。该代码遗漏了其他一些重要部分,我不完全确定如何使用它。尝试了不同的事情,但到目前为止运气不佳。另一件事是我没有太多的时间去检查所有的选项,但我会继续尝试。好的,这个答案看起来是正确的。我可以在一次导入中转移1000个帖子。看起来1000是一个新的限制。比50强多了。所以我接受这个。谢谢@PrayagVerma。这实际上是一个完整的答案。1000篇文章的限制原来是livejournal限制,而不是blogger限制。
# build feed
request_feed = gdata.base.GBaseItemFeed(atom_id=atom.Id(text='test batch'))
# format each object 
entry1 = gdata.base.GBaseItemFromString('--XML for your new item goes here--')
entry1.title.text = 'first batch request item'
entry2 = gdata.base.GBaseItemFromString('--XML for your new item here--')
entry2.title.text = 'second batch request item'

# Add each blog item to the request feed 
request_feed.AddInsert(entry1)
request_feed.AddInsert(entry2)

# Execute the batch processes through the request_feed (all items)
result_feed = gd_client.ExecuteBatch(request_feed)
livejournal2blogger.sh -u <username> -p <password> [-s <server>]
PYTHONPATH=${PROJ_DIR}/lib python ${PROJ_DIR}/src/livejournal2blogger/lj2b.py $*
PYTHONPATH=${PROJ_DIR}/lib python2.5 ${PROJ_DIR}/src/livejournal2blogger/lj2b.py $*