changeset 6:3cb8ad35fe62

make a dummy front end
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 25 Nov 2010 13:07:37 -0800
parents 50f77774a20a
children dfbb21128332
files bitsytweet/__init__.py
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bitsytweet/__init__.py
+++ b/bitsytweet/__init__.py
@@ -1,18 +1,54 @@
 """
 BitsyTweet
 """
 
+import sys
 import twitter
 
 class BitsyTweet(object):
 
   def __init__(self, bitsyblog, username, password):
     self.bitsyblog = bitsyblog
     self.username = username
     self.password = password
     self.api = twitter.Api(username=self.username, password=self.password) 
 
   def __call__(self, blog_entry, url):
     if blog_entry.privacy == 'public': # only tweet public blogs
       tweet = '%s : %s' % (blog_entry.snippet(), url)
       self.api.PostUpdate(tweet)
+
+def main(args=sys.argv[1:]):
+  """debugging front-end for BitstTweet"""
+  
+  usage = "%prog [options] tweet"
+  from optparse import OptionParser
+  parser = OptionParser(usage=usage)
+  parser.add_option('-u', '--username',
+                    help='username')
+  parser.add_option('-p', '--password',
+                    help='password')
+  options, args = parser.parse_args(args)
+  if not options.username:
+    parser.error('please provide a username')
+  if not options.password:
+    parser.error('please provide a password')
+  if not args:
+    parser.error('please provide a post')
+
+  # get the tweeter
+  bitsytweet = BitsyTweet(None, options.username, options.password)
+
+  # make a dummy class
+  class Dummy(object):
+    def __init__(self, tweet):
+      self.tweet = tweet
+    def snippet(self):
+      return self.tweet
+  blog_entry = Dummy(' '.join(args))
+
+  # tweet it
+  bitsytweet(blog_entry, 'http://k0s.org/blog')
+
+if __name__ == '__main__':
+  main()