Batch blog posting using python gdata client

I am trying to copy all my posts in Livejournal to my new blog at blogger.com. I do this using a slightly modified example that comes with the python gdata client . I have a json file with all my posts imported from Livejournal. The problem is that blogger.com has a daily limit for publishing new blog entries per day - 50, so you can imagine that the 1300+ posts that I will have will be copied in a month, since I can’t programmatically enter captcha after 50 imports.

I recently found out that there is also a batch mode somewhere in gdata, but I could not figure out how to use it. Googling really didn't help.

Any advice or help would be greatly appreciated.

Thanks.

Update

Just in case, I use the following code

#!/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) 
+7
python batch-processing blogger
source share
2 answers

Instead, I would recommend using Google Blog converters ( https://code.google.com/archive/p/google-blog-converters-appengine/ )

To get started, you have to go through

https://github.com/google/gdata-python-client/blob/master/INSTALL.txt - Steps to configure the Google GData API https://github.com/pra85/google-blog-converters-appengine/blob/ master / README.txt - Steps for Using Blog Converters

Once you have all the settings, you will need to run the following command (its username and password LiveJournal)

 livejournal2blogger.sh -u <username> -p <password> [-s <server>] 

Redirect your output to an XML file. This file can now be imported directly into Blogger's blog by going to Blogger Dashboard, your blog> Settings > Other > Blog Tools > Import Blog

Here, be sure to check the Automatically publish all imported posts and pages option. I tried this before when in a blog with over 400 posts, Blogger successfully imported and published them without any problems.

If in doubt, Blogger may have some problems (because the number of posts is quite large), or you have other Blogger blogs in your account. Then, just for the sake of caution, create a separate Blogger (Google) account, and then try importing posts. After that, you can transfer the administrative controls to your real Blogger account (to transfer you first need to send an invitation to the author, then raise the real Blogger account to the administrator level and, finally, delete the dummy account. Settings> General> Permissions> Authors blog)

Also make sure you are using Python 2.5, otherwise these scripts will not work. Before starting livejournal2blogger.sh, change the following line (Thanks for Michael Fleet for this fix http://michael.f1337.us/2011/12/28/google-blog-converters-blogger2wordpress/ )

 PYTHONPATH=${PROJ_DIR}/lib python ${PROJ_DIR}/src/livejournal2blogger/lj2b.py $* 

to

 PYTHONPATH=${PROJ_DIR}/lib python2.5 ${PROJ_DIR}/src/livejournal2blogger/lj2b.py $* 

PS I know this is not the answer to your question, but since the purpose of this answer is the same as your question (to import more than 50 messages per day), thats why I shared it. I am not very good at Python or GData API, I set up the environment and performed these steps to answer this question (and I managed to import posts from LiveJournal to Blogger with it).

+15
source share

http://nullege.com/codes/search/gdata has good resources

 # 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) 
+6
source share

All Articles