-def no_action(twitter, options):
- print >> sys.stderr, "No such action: ", options['action']
- sys.exit(1)
+def get_status_formatter(options):
+ sf = formatters.get(options['format'])
+ if (not sf):
+ raise TwitterError(
+ "Unknown formatter '%s'" %(options['format']))
+ return sf()
+
+class Action(object):
+ pass
+
+class NoSuchAction(Action):
+ def __call__(self, twitter, options):
+ print >> sys.stderr, "No such action: ", options['action']
+ sys.exit(1)
+
+class StatusAction(Action):
+ def __call__(self, twitter, options):
+ statuses = self.getStatuses(twitter)
+ sf = get_status_formatter(options)
+ for status in statuses:
+ statusStr = sf(status)
+ if statusStr.strip():
+ print statusStr.encode(sys.stdout.encoding, 'replace')
+
+class FriendsAction(StatusAction):
+ def getStatuses(self, twitter):
+ return reversed(twitter.statuses.friends_timeline())