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 = ""
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()
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:
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):
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):
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):