diff options
author | Sean B. Palmer <sean@miscoranda.com> | 2013-03-15 15:28:03 +0000 |
---|---|---|
committer | Sean B. Palmer <sean@miscoranda.com> | 2013-03-15 15:28:03 +0000 |
commit | a546977f70f9b8c4acac632972cd26a2dd8d7676 (patch) | |
tree | ccdb1156c342d0f861e177df2b425d32a0ca3119 /modules/search.py | |
parent | 7752b56cc2f8325883bad052ad31bf2e7feb706e (diff) | |
download | bot-a546977f70f9b8c4acac632972cd26a2dd8d7676.tar.gz bot-a546977f70f9b8c4acac632972cd26a2dd8d7676.tar.bz2 bot-a546977f70f9b8c4acac632972cd26a2dd8d7676.zip |
A new scheduling command and some improvements to gc
Diffstat (limited to 'modules/search.py')
-rwxr-xr-x | modules/search.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/modules/search.py b/modules/search.py index 89e57b2..5d038af 100755 --- a/modules/search.py +++ b/modules/search.py @@ -204,7 +204,7 @@ suggest.commands = ['suggest'] def new_gc(query): uri = 'https://www.google.com/search?hl=en&q=' uri = uri + web.urllib.quote(query).replace('+', '%2B') - if '"' in query: uri += '&tbs=li:1' + # if '"' in query: uri += '&tbs=li:1' bytes = web.get(uri) if "did not match any documents" in bytes: return "0" @@ -212,6 +212,26 @@ def new_gc(query): return result return None +def newest_gc(query): + uri = 'https://www.google.com/search?hl=en&q=' + uri = uri + web.urllib.quote(query).replace('+', '%2B') + bytes = web.get(uri + '&tbs=li:1') + if "did not match any documents" in bytes: + return "0" + for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes): + return result + return None + +def newerest_gc(query): + uri = 'https://www.google.com/search?hl=en&q=' + uri = uri + web.urllib.quote(query).replace('+', '%2B') + bytes = web.get(uri + '&prmd=imvns&start=950') + if "did not match any documents" in bytes: + return "0" + for result in re.compile(r'(?ims)([0-9,]+) results?').findall(bytes): + return result + return None + def ngc(phenny, input): if not input.group(2): return phenny.reply("No query term.") @@ -229,9 +249,13 @@ def gc(phenny, input): if not input.group(2): return phenny.reply("No query term.") query = input.group(2).encode('utf-8') - old = old_gc(query) or "?" - new = new_gc(query) or "?" - phenny.say(query + ": " + old + " / " + new) + result = query + ": " + result += (old_gc(query) or "?") + " (api)" + result += ", " + (newerest_gc(query) or "?") + " (end)" + result += ", " + (new_gc(query) or "?") + " (site)" + if '"' in query: + result += ", " + (newest_gc(query) or "?") + " (verbatim)" + phenny.say(result) gc.commands = ['gc'] gc.priority = 'high' |