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