From efa0c410a353fd98e844862a60addc25faa992f9 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Tue, 17 Nov 2009 20:24:23 -0700 Subject: [PATCH] better twitter.py error messages --- plugins/twitter.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/twitter.py b/plugins/twitter.py index d887d81..0a6ad31 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -47,11 +47,11 @@ def twitter(inp): if int(num) > 3200: return 'error: only supports up to the 3200th tweet' url += '/statuses/user_timeline/%s.xml?count=1&page=%s' % (name, num) - elif re.match(r'^#\w{1,15}$', inp): + elif re.match(r'^#\w+$', inp): url = 'http://search.twitter.com/search.atom?q=%23' + inp[1:] searching_hashtag = True else: - return 'error: invalid username' + return 'error: invalid request' try: xml = urllib2.urlopen(url).read() @@ -72,8 +72,12 @@ def twitter(inp): if searching_hashtag: ns = '{http://www.w3.org/2005/Atom}' - id = random.choice(tweet.findall(ns + 'entry/' + ns + 'id')).text + tweets = tweet.findall(ns + 'entry/' + ns + 'id') + if not tweets: + return 'error: hashtag not found' + id = random.choice(tweets).text id = id[id.rfind(':') + 1:] + print id return twitter(id) if not getting_id: