From bc84e9e2d9a2495b18d06de6e144616106e67e4b Mon Sep 17 00:00:00 2001 From: Bryan Koroleski Date: Tue, 30 Jul 2013 15:47:01 -0500 Subject: [PATCH] Re-added support for getting the nth tweet on a user's timeline. --- plugins/twitter.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/twitter.py b/plugins/twitter.py index 2f2acff..005e323 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -9,7 +9,8 @@ from util import hook, http @hook.api_key('twitter') @hook.command def twitter(inp, api_key=None): - ".twitter / -- get 's last tweet/get tweet " + ".twitter / / -- " \ + "get 's last/th tweet/get tweet " if not isinstance(api_key, dict) or any(key not in api_key for key in ('consumer', 'consumer_secret', 'access', 'access_secret')): @@ -21,6 +22,15 @@ def twitter(inp, api_key=None): getting_id = True request_url = "https://api.twitter.com/1.1/statuses/show.json?id=%s" % inp else: + try: + inp, index = re.split('\s+', inp, 1) + index = int(index) + except ValueError: + index = 0 + if index < 0: + index = 0 + if index >= 20: + return 'error: only supports up to the 20th tweet' request_url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=%s" % inp try: @@ -41,7 +51,10 @@ def twitter(inp, api_key=None): return 'error: unknown %s' % e.code if not getting_id: - tweet = tweet[0] + try: + tweet = tweet[index] + except IndexError: + return 'error: user does not have that many tweets' text = tweet["text"] screen_name = tweet["user"]["screen_name"]