Post to Twitter from Shell - Python Version


/ Published in: Python
Save to your folder(s)

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`


Copy this code and paste it in your HTML
  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)

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.