Well, I've transfer my blog couple times,
so it's has some image link from other static web hosting,
but someday, I got a mail that told me the service has expired,
because my adsl account has expired long time ago.
So, I thought, maybe I can move all file to other web hosting,
and replace all string in blogger.
then I try to find a solution or any way to replace a string in all article,
but I can't after I google it.
So I try to wrote it.
refer to
Blogger API Developer's Guide: PythonSource:
def ReciveAll(self):
# Request the feed.
query = gdata.blogger.client.Query(max_results=9999)
feed = self.client.get_posts(self.blog_id ,query=query)
return feed
def SearchAll(self,str):
result = []
feed = self.ReciveAll()
for entry in feed.entry:
if (string.find(entry.content.text, str) != -1):
result.append(entry)
return result
def UpdatePost(self, entry_to_update):
return self.client.update(entry_to_update)
def main():
global email
global password
"""The main function runs the BloggerExample application.
NOTE: It is recommended that you run this sample using a test account.
"""
email = easygui.enterbox('Email:','Login')
password = easygui.passwordbox('Password:','Login')
sample = BloggerExample()
while 1:
array = []
menu_array = ['Search','Exit','Search and replace']
menu_choice = easygui.choicebox('Main menu', 'Main menu', menu_array)
#select = raw_input("1:Search\n2:Search and replace\n3:exit\n")
if menu_choice == 'Search':
#user_input = raw_input("Search:").decode(sys.stdin.encoding)
user_input = easygui.enterbox('Search:','Search')
results = sample.SearchAll(user_input)
for entry in results:
array.append(entry.title.text.encode("utf8"))
entry_choice = easygui.choicebox("test","test",array)
while(entry_choice!= None):
re_split=re.compile("[<>]")
for entry in results:
if entry.title.text == entry_choice:
line_array = re_split.split(entry.content.text.encode("utf8"))
line_array_contain = []
for line in line_array:
if line.find(user_input.encode("utf8")) != -1:
line_array_contain.append(line)
easygui.choicebox("Search Result","Search",line_array_contain)
break
entry_choice = easygui.choicebox("test","test",array)
elif menu_choice == 'Search and replace':
#src = raw_input("Search:").decode(sys.stdin.encoding)
src = easygui.enterbox('Search:','Search and Replace')
#dest = raw_input("Replace:").decode(sys.stdin.encoding)
dest = easygui.enterbox('Replace:','Search and Replace')
if easygui.ccbox():
results = sample.SearchAll(src)
for entry in results:
entry.content.text = entry.content.text.replace(src,dest)
#print entry.content.text
sample.UpdatePost(entry)
#print entry.title.text + "-> done"
easygui.msgbox(entry.title.text + "-> done")
elif menu_choice == 'Exit':
break
if __name__ == '__main__':
main()
GUI Version:
Source:
http://dl.dropbox.com/u/3357679/Blog/Src_Blogger_search_replace_gui.7zPrebuilt binary:
http://dl.dropbox.com/u/3357679/Blog/Blogger_search_replace_gui.7zConsole Version:
Source:
http://dl.dropbox.com/u/3357679/Blog/Src_Blogger_search_replace.7zPrebuilt binary:
http://dl.dropbox.com/u/3357679/Blog/Blogger_search_replace.7zbecause that's practice program(it's mean beta release,
use it at your own risk!)
please backup or export the blog before.
I've try replace in English and Traditional Chinese,
it's work, so, it's
should support multi language.
Finally, it's worked!
but I found that maybe I need modify article by manually,
because it's look like upload image to Picasa will be much better?