def post_twit(username,password,message):
import urllib, urlib2, base64
import gluon.contrib.simplejson as sj
args= urllib.urlencode([('status',message)])
headers={}
headers['Authorization'] = 'Basic '+base64.b64encode(username+':'+password)
request = urllib2.Request('http://twitter.com/statuses/update.json', args, headers)
return sj.loads(urllib2.urlopen(req).read())
def get_twits():
user='web2py'
import gluon.tools
import gluon.contrib.simplejson as sj
page = gluon.tools.fetch('http://twitter.com/%s?format=json' % user)
tweets=XML(sj.loads(page)['#timeline'])
return dict(tweets=tweets)
No third party libraries required. Just old plain web2py.