plugins/twitter: pick a random search result for hashtags
This commit is contained in:
parent
4fd611da09
commit
a97715d5c0
|
@ -17,6 +17,7 @@ def twitter(inp, api_key=None):
|
||||||
|
|
||||||
getting_id = False
|
getting_id = False
|
||||||
doing_search = False
|
doing_search = False
|
||||||
|
index_specified = False
|
||||||
|
|
||||||
if re.match(r'^\d+$', inp):
|
if re.match(r'^\d+$', inp):
|
||||||
getting_id = True
|
getting_id = True
|
||||||
|
@ -25,6 +26,7 @@ def twitter(inp, api_key=None):
|
||||||
try:
|
try:
|
||||||
inp, index = re.split('\s+', inp, 1)
|
inp, index = re.split('\s+', inp, 1)
|
||||||
index = int(index)
|
index = int(index)
|
||||||
|
index_specified = True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
index = 0
|
index = 0
|
||||||
if index < 0:
|
if index < 0:
|
||||||
|
@ -58,6 +60,8 @@ def twitter(inp, api_key=None):
|
||||||
if doing_search:
|
if doing_search:
|
||||||
try:
|
try:
|
||||||
tweet = tweet["statuses"]
|
tweet = tweet["statuses"]
|
||||||
|
if not index_specified:
|
||||||
|
index = random.randint(0, len(tweet) - 1)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return 'error: no results'
|
return 'error: no results'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue