We Recommend

Learning Python Learning Python
The authors of Learning Python show you enough essentials of the Python scripting language to enable you to begin solving problems right away, then reveal more powerful aspects of the language one at a time. This approach is sure to appeal to programmers and system administrators who have urgent problems and a preference for learning by semi-guided experimentation.


Posted By

sgraber on 04/22/08


Tagged

python appengine


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

leighmac
taboularasa


Posting to Twitter from Google AppEngine


Published in: Python 


URL: http://highscalability.com/using-google-appengine-little-micro-scalability

A way to post to twitter from Google AppEngine using urlfetch.

  1. class SendChime(webapp.RequestHandler):
  2. def get(self):
  3. self.response.headers['Content-Type'] = 'text/plain'
  4. username = self.request.get("username")
  5.  
  6. login = username
  7. password = "password"
  8. chime = self.get_chime()
  9. payload= {'status' : chime, 'source' : "innertwitter"}
  10. payload= urllib.urlencode(payload)
  11.  
  12. base64string = base64.encodestring('%s:%s' % (login, password))[:-1]
  13. headers = {'Authorization': "Basic %s" % base64string}
  14.  
  15. url = "http://twitter.com/statuses/update.xml"
  16. result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST, headers=headers)
  17.  
  18. self.response.out.write(result.content)
  19.  
  20. def get_chime(self):
  21. now = datetime.datetime.now()
  22. chime = "........*chime*.............." + now.ctime()
  23. return chime
  24.  
  25. def main():
  26. application = webapp.WSGIApplication(
  27. [('/innertwitter', InnerTwitter),
  28. ('/sendchime', SendChime)],
  29. debug=True)

Report this snippet 

You need to login to post a comment.