]> jfr.im git - z_archive/twitter.git/commitdiff
Bugfixes, cleanup on follow/leave feature
authorMike Verdone <redacted>
Sun, 15 Feb 2009 21:15:13 +0000 (14:15 -0700)
committerMike Verdone <redacted>
Sun, 15 Feb 2009 21:15:13 +0000 (14:15 -0700)
twitter/api.py
twitter/cmdline.py

index 30302e31cc92396568bb9dd6cb8ca672fe01b91a..e22fb468e15b770cdf1d096bd830ca55fa8341e2 100644 (file)
@@ -42,11 +42,16 @@ class TwitterCall(object):
                 self.username, self.password, self.format, self.domain,
                 self.uri + "/" + k)
     def __call__(self, **kwargs):
+        uri = self.uri
         method = "GET"
         for action in _POST_ACTIONS:
             if self.uri.endswith(action):
                 method = "POST"
                 break
+        
+        id = kwargs.pop('id', None)
+        if id:
+            uri += "/%s" %(id)
             
         encoded_kwargs = urlencode(kwargs.items())
         argStr = ""
@@ -64,7 +69,7 @@ class TwitterCall(object):
         c = httplib.HTTPConnection(self.domain)
         try:
             c.putrequest(method, "%s.%s%s" %(
-                self.uri, self.format, argStr))
+                uri, self.format, argStr))
             for item in headers.iteritems():
                 c.putheader(*item)
             c.endheaders()
@@ -76,12 +81,8 @@ class TwitterCall(object):
                 return []
             elif (r.status != 200):
                 raise TwitterError(
-                                       "Twitter sent status %i for URL: %s.%s using parameters: %s\ndetails: %s" %(
-                    r.status, 
-                                       self.uri, 
-                                       self.format,
-                                       encoded_kwargs, 
-                                       r.read()))
+                    "Twitter sent status %i for URL: %s.%s using parameters: (%s)\ndetails: %s" %(
+                        r.status, uri, self.format, encoded_kwargs, r.read()))
             if "json" == self.format:
                 return json.loads(r.read())
             else:
index d72c44d952455cf04eaea0f3b9f95139278df54f..bff33c5bee3f7b529724f346bda41e0c13cab043 100644 (file)
@@ -107,8 +107,11 @@ class URLStatusFormatter(object):
 
 class AdminFormatter(object):
     def __call__(self, action, user):
-        return(u"%s: %s" %(
-            "Following" if action == "follow" else "Leaving", user['name']))
+        user_str = u"%s (%s)" %(user['screen_name'], user['name'])
+        if action == "follow":
+            return u"You are now following %s" %(user_str)
+        else:
+            return u"You are no longer following %s" %(user_str)
 
 class VerboseAdminFormatter(object):
     def __call__(self, action, user):
@@ -167,11 +170,11 @@ class StatusAction(Action):
 
 class AdminAction(Action):
     def __call__(self, twitter, options):
-        if (not options['extra_args'][0]):
+        if not options['extra_args'][0]:
             raise TwitterError("You need to specify a User (Screen Name)")
         af = get_admin_formatter(options)
         user = self.getUser(twitter, options['extra_args'][0])
-        if(user):
+        if user:
             print af(options['action'], user).encode(sys.stdout.encoding, 'replace')
 
 class FriendsAction(StatusAction):
@@ -188,12 +191,11 @@ class RepliesAction(StatusAction):
 
 class FollowAction(AdminAction):
     def getUser(self, twitter, user):
-        # Twitter wants /notifications/follow/user.json?id=user
-        return twitter.notifications.follow.__getattr__(user)(id=user)
+        return twitter.notifications.follow(id=user)
 
 class LeaveAction(AdminAction):
     def getUser(self, twitter, user):
-        return twitter.notifications.leave.__getattr__(user)(id=user)
+        return twitter.notifications.leave(id=user)
 
 class SetStatusAction(Action):
     def __call__(self, twitter, options):