+ printNicely(statusStr)
+
+class SearchAction(Action):
+ def __call__(self, twitter, options):
+ # We need to be pointing at search.twitter.com to work, and it is less
+ # tangly to do it here than in the main()
+ twitter.domain="search.twitter.com"
+ twitter.uriparts=()
+ # We need to bypass the TwitterCall parameter encoding, so we
+ # don't encode the plus sign, so we have to encode it ourselves
+ query_string = "+".join(
+ [quote(term)
+ for term in options['extra_args']])
+
+ results = twitter.search(q=query_string)['results']
+ f = get_formatter('search', options)
+ for result in results:
+ resultStr = f(result, options)
+ if resultStr.strip():
+ printNicely(resultStr)
+
+class AdminAction(Action):
+ def __call__(self, twitter, options):
+ if not (options['extra_args'] and options['extra_args'][0]):
+ raise TwitterError("You need to specify a user (screen name)")
+ af = get_formatter('admin', options)
+ try:
+ user = self.getUser(twitter, options['extra_args'][0])
+ except TwitterError as e:
+ print("There was a problem following or leaving the specified user.")
+ print("You may be trying to follow a user you are already following;")
+ print("Leaving a user you are not currently following;")
+ print("Or the user may not exist.")
+ print("Sorry.")
+ print()
+ print(e)
+ else:
+ printNicely(af(options['action'], user))
+
+class ListsAction(StatusAction):
+ def getStatuses(self, twitter, options):
+ if not options['extra_args']:
+ raise TwitterError("Please provide a user to query for lists")
+
+ screen_name = options['extra_args'][0]
+
+ if not options['extra_args'][1:]:
+ lists = twitter.user.lists(user=screen_name)['lists']
+ if not lists:
+ printNicely("This user has no lists.")
+ for list in lists:
+ lf = get_formatter('lists', options)
+ printNicely(lf(list))
+ return []
+ else:
+ return reversed(twitter.user.lists.list.statuses(
+ user=screen_name, list=options['extra_args'][1]))
+
+
+class MyListsAction(ListsAction):
+ def getStatuses(self, twitter, options):
+ screen_name = twitter.account.verify_credentials()['screen_name']
+ options['extra_args'].insert(0, screen_name)
+ return ListsAction.getStatuses(self, twitter, options)
+
+