Pulled fixed version of suggest.py from upstream (fixed by stoneLeaf)
This commit is contained in:
parent
0998cc6709
commit
d6881d4ece
1 changed files with 5 additions and 5 deletions
|
@ -15,19 +15,19 @@ def suggest(inp, inp_unstripped=''):
|
|||
num, inp = m.groups()
|
||||
num = int(num)
|
||||
if num > 10:
|
||||
return 'I can only get the first ten suggestions.'
|
||||
return 'can only get first ten suggestions'
|
||||
else:
|
||||
num = 0
|
||||
|
||||
page = http.get('http://google.com/complete/search', q=inp)
|
||||
page = http.get('http://google.com/complete/search', output='json', client='hp', q=inp)
|
||||
page_json = page.split('(', 1)[1][:-1]
|
||||
suggestions = json.loads(page_json)[1]
|
||||
if not suggestions:
|
||||
return 'No suggestions found :('
|
||||
return 'no suggestions found'
|
||||
if num:
|
||||
if len(suggestions) + 1 <= num:
|
||||
return 'I only got %d suggestions.' % len(suggestions)
|
||||
return 'only got %d suggestions' % len(suggestions)
|
||||
out = suggestions[num - 1]
|
||||
else:
|
||||
out = random.choice(suggestions)
|
||||
return '#%d: %s' % (int(out[2][0]) + 1, out[0])
|
||||
return '#%d: %s' % (int(out[2][0]) + 1, out[0].replace('<b>', '').replace('</b>', ''))
|
Reference in a new issue