Posted By

nate_smith on 08/14/08


Tagged

Shell python web20 twitter


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

noah
DrewDouglass
ibito


Post to Twitter from Shell - Python Version


 / Published in: Python
 

URL: http://snipplr.com/view/2352/twitter-from-the-command-line-using-curl/

inspired by http://snipplr.com/view/6594/post-to-twitter-from-the-shell/ . I just rewrote it in Python because I didn't want to install a Ruby interpreter :)

use chmod +x tweet.py to run it as ./tweet.py instead of python tweet.py

  1. #!/usr/bin/python
  2. # tweet.py
  3. # usage:
  4. # tweet.py message
  5. #
  6. # inpired by:
  7.  
  8. import sys
  9. from os import popen
  10.  
  11. def tweet( message, user, password ):
  12. print 'posting %s for %s' % (message, user)
  13.  
  14. url = 'http://twitter.com/statuses/update.xml'
  15. curl = 'curl -s -u %s:%s -d status="%s" %s' % (user,password,message,url)
  16.  
  17. pipe = popen(curl, 'r')
  18.  
  19. if __name__ == '__main__':
  20. if len(sys.argv) != 2:
  21. print "Usage: tweet.py <message>"
  22. sys.exit()
  23.  
  24. message = sys.argv[1]
  25. if len(message) > 140:
  26. print "Message too long"
  27. sys.exit()
  28.  
  29. user = raw_input('Username: ')
  30. password = raw_input('Password: ')
  31.  
  32. tweet(message, user, password)

Report this snippet  

You need to login to post a comment.