better twitter.py error messages
This commit is contained in:
parent
692fbde76c
commit
efa0c410a3
|
@ -47,11 +47,11 @@ def twitter(inp):
|
||||||
if int(num) > 3200:
|
if int(num) > 3200:
|
||||||
return 'error: only supports up to the 3200th tweet'
|
return 'error: only supports up to the 3200th tweet'
|
||||||
url += '/statuses/user_timeline/%s.xml?count=1&page=%s' % (name, num)
|
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:]
|
url = 'http://search.twitter.com/search.atom?q=%23' + inp[1:]
|
||||||
searching_hashtag = True
|
searching_hashtag = True
|
||||||
else:
|
else:
|
||||||
return 'error: invalid username'
|
return 'error: invalid request'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml = urllib2.urlopen(url).read()
|
xml = urllib2.urlopen(url).read()
|
||||||
|
@ -72,8 +72,12 @@ def twitter(inp):
|
||||||
|
|
||||||
if searching_hashtag:
|
if searching_hashtag:
|
||||||
ns = '{http://www.w3.org/2005/Atom}'
|
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:]
|
id = id[id.rfind(':') + 1:]
|
||||||
|
print id
|
||||||
return twitter(id)
|
return twitter(id)
|
||||||
|
|
||||||
if not getting_id:
|
if not getting_id:
|
||||||
|
|
Loading…
Reference in New Issue