下面的代码可将twitter同步到sina微博。不过,还不能移植到GAE.
#!/usr/bin/env python # -*- coding: utf-8 -*- #to ensure the utf8 encoding environment import sys default_encoding = 'utf-8' if sys.getdefaultencoding() != default_encoding: reload(sys) sys.setdefaultencoding(default_encoding) import urllib import urllib2,cookielib class Twitter(db.Model): id=db.StringProperty() def send_sina_msgs(username,password,msgs): cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) data = 'username=%s&password=%s&returntype=TEXT'%(username,password) request = urllib2.Request( url = 'https://login.sina.com.cn/sso/login.php', data = data) ret = opener.open(request) #content = ret.read() for msg in msgs: data = 'content=%s'%(msg) request = urllib2.Request( url = 'http://t.sina.com.cn/mblog/publish.php', headers = {'Referer':'http://t.sina.com.cn'}, data = data) ret = opener.open(request) #content = ret.read() #print content