summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSean B. Palmer <http://inamidst.com/sbp/>2008-11-20 10:18:21 +0000
committerSean B. Palmer <http://inamidst.com/sbp/>2008-11-20 10:18:21 +0000
commit1856781604aef3f339ec1e5c06d95c92a1ce300f (patch)
tree6c547efddd677a4d66cc1adca67e3803894b1d5d /modules
parentfe16d21212bacc9704a6cd84d3c85a6676936181 (diff)
downloadbot-1856781604aef3f339ec1e5c06d95c92a1ce300f.tar.gz
bot-1856781604aef3f339ec1e5c06d95c92a1ce300f.tar.bz2
bot-1856781604aef3f339ec1e5c06d95c92a1ce300f.zip
Updated the search facilities.
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/oblique.py2
-rwxr-xr-xmodules/search.py23
2 files changed, 12 insertions, 13 deletions
diff --git a/modules/oblique.py b/modules/oblique.py
index a4aba17..a680b6d 100755
--- a/modules/oblique.py
+++ b/modules/oblique.py
@@ -24,7 +24,7 @@ def mappings(uri):
command, template = item.split(' ', 1)
if not template.startswith('http://'): continue
- result[command] = template
+ result[command] = template.replace('&amp;', '&')
return result
def o(phenny, input):
diff --git a/modules/search.py b/modules/search.py
index b1123b8..4fcaabc 100755
--- a/modules/search.py
+++ b/modules/search.py
@@ -22,24 +22,24 @@ def json(text):
print text
raise ValueError('Input must be serialised JSON.')
-def search(query, n=1):
- """Search using SearchMash, return its JSON."""
- q = web.urllib.quote(query.encode('utf-8'))
- uri = 'http://www.searchmash.com/results/' + q + '?n=' + str(n)
- bytes = web.get(uri)
+def search(query):
+ """Search using AjaxSearch, and return its JSON."""
+ uri = 'http://ajax.googleapis.com/ajax/services/search/web'
+ args = '?v=1.0&safe=off&q=' + web.urllib.quote(query.encode('utf-8'))
+ bytes = web.get(uri + args)
return json(bytes)
def result(query):
results = search(query)
- if results['results']:
- return results['results'][0]['url']
+ if results['responseData']:
+ return results['responseData']['results'][0]['unescapedUrl']
return None
def count(query):
results = search(query)
- if not results['results']:
+ if not results['responseData'] or not results['responseData']['cursor']:
return '0'
- return results['estimatedCount']
+ return results['responseData']['cursor']['estimatedResultCount']
def formatnumber(n):
"""Format a number with beautiful commas."""
@@ -66,11 +66,10 @@ g.example = '.g swhack'
def gc(phenny, input):
"""Returns the number of Google results for the specified input."""
- if input.nick == 'goatov': return
query = input.group(2)
if not query:
return phenny.reply('.gc what?')
- num = count(query)
+ num = formatnumber(count(query))
phenny.say(query + ': ' + num)
gc.commands = ['gc']
gc.priority = 'high'
@@ -88,7 +87,7 @@ def gcs(phenny, input):
results = []
for i, query in enumerate(queries):
query = query.strip('[]')
- n = int((count(query) or '0').replace(',', ''))
+ n = int((formatnumber(count(query)) or '0').replace(',', ''))
results.append((n, query))
if i >= 2: __import__('time').sleep(0.25)
if i >= 4: __import__('time').sleep(0.25)