]> jfr.im git - z_archive/twitter.git/commitdiff
Do not provide a default agent string. Add help action.
authorMike Verdone <redacted>
Sun, 15 Feb 2009 21:50:32 +0000 (14:50 -0700)
committerMike Verdone <redacted>
Sun, 15 Feb 2009 21:50:32 +0000 (14:50 -0700)
twitter/api.py
twitter/cmdline.py

index 02274c650e8c6828ef49b218f7d5ed7a5b99ef00..52db9739be8821be4b651f7ea93b5f62cb49290b 100644 (file)
@@ -29,9 +29,7 @@ _POST_ACTIONS = [
 
 class TwitterCall(object):
     def __init__(
-        self, username, password, format, domain, uri="",
-        agent="Python Twitter Tools"
-    ):
+        self, username, password, format, domain, uri="", agent=None):
         self.username = username
         self.password = password
         self.format = format
@@ -44,8 +42,7 @@ class TwitterCall(object):
         except AttributeError:
             return TwitterCall(
                 self.username, self.password, self.format, self.domain,
-                self.uri + "/" + k, self.agent
-            )
+                self.uri + "/" + k, self.agent)
     def __call__(self, **kwargs):
         uri = self.uri
         method = "GET"
@@ -162,7 +159,9 @@ class Twitter(TwitterCall):
       The output will not be parsed in any way. It will be a raw string
       of XML.
     """
-    def __init__(self, email=None, password=None, format="json", domain="twitter.com"):
+    def __init__(
+        self, email=None, password=None, format="json", domain="twitter.com",
+        agent=None):
         """
         Create a new twitter API connector using the specified
         credentials (email and password). Format specifies the output
index f57dbf93b0e45d97213ef781f4270ee62358c9cf..c8506c3f0b2c16947cace800bb93efcd678a009b 100644 (file)
@@ -6,6 +6,7 @@ USAGE:
 ACTIONS:
  follow         add the specified user to your follow list
  friends        get latest tweets from your friends (default action)
+ help           print this help text that you are currently reading
  leave          remove the specified user from your following list
  public         get latest public tweets
  replies        get latest replies
@@ -48,6 +49,8 @@ from ConfigParser import SafeConfigParser
 
 from api import Twitter, TwitterError
 
+AGENT_STR = "Twitter Command-line Tool"
+
 options = {
     'email': None,
     'password': None,
@@ -182,6 +185,7 @@ class AdminAction(Action):
             print "  Or the user may not exist."
             print "  Sorry."
             print
+            print e
         else:
             print af(options['action'], user).encode(sys.stdout.encoding, 'replace')
 
@@ -213,9 +217,14 @@ class SetStatusAction(Action):
         status = (statusTxt.encode('utf8', 'replace'))
         twitter.statuses.update(status=status)
 
+class HelpAction(Action):
+    def __call__(self, twitter, options):
+        print __doc__
+
 actions = {
     'follow': FollowAction,
     'friends': FriendsAction,
+    'help': HelpAction,
     'leave': LeaveAction,
     'public': PublicAction,
     'replies': RepliesAction,
@@ -250,8 +259,10 @@ def main_with_args(args):
         
     if options['email'] and not options['password']:
         options['password'] = getpass("Twitter password: ")
-    twitter = Twitter(options['email'], options['password'])
+        
+    twitter = Twitter(options['email'], options['password'], agent=AGENT_STR)
     action = actions.get(options['action'], NoSuchAction)()
+    
     try:
         doAction = lambda : action(twitter, options)