From 90cb5bf47d4711a7ae28be0833524d3457774f3f Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Fri, 20 Nov 2009 16:55:39 -0700 Subject: [PATCH] use py2.6 json module instead of yaml as a json decoder --- plugins/babel.py | 7 ++++--- plugins/google.py | 7 ++++--- plugins/suggest.py | 9 +++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/babel.py b/plugins/babel.py index 23e4be4..f12c3a6 100644 --- a/plugins/babel.py +++ b/plugins/babel.py @@ -1,8 +1,9 @@ import urllib import htmlentitydefs import re +import json -from util import hook, yaml +from util import hook ########### from http://effbot.org/zone/re-sub.htm#unescape-html ############# @@ -39,8 +40,8 @@ def goog_trans(text, slang, tlang): req_url = 'http://ajax.googleapis.com/ajax/services/language/translate' \ '?v=1.0&q=%s&langpair=%s' url = req_url % (urllib.quote(text, safe=''), slang + '%7C' + tlang) - json = urllib.urlopen(url).read() - parsed = yaml.load(json) + page = urllib.urlopen(url).read() + parsed = json.loads(page) if not 200 <= parsed['responseStatus'] < 300: raise IOError('error with the translation server: %d: %s' % ( parsed['responseStatus'], '')) diff --git a/plugins/google.py b/plugins/google.py index 4d5a322..e2047e6 100644 --- a/plugins/google.py +++ b/plugins/google.py @@ -1,16 +1,17 @@ import urllib import random from lxml import html +import json -from util import hook, yaml +from util import hook def api_get(kind, query): req_url = 'http://ajax.googleapis.com/ajax/services/search/%s?' \ 'v=1.0&safe=off&q=%s' url = req_url % (kind, urllib.quote(query, safe='')) - json = urllib.urlopen(url).read() - return yaml.load(json) + page = urllib.urlopen(url).read() + return json.loads(page) @hook.command diff --git a/plugins/suggest.py b/plugins/suggest.py index a42dcdc..55cbf12 100644 --- a/plugins/suggest.py +++ b/plugins/suggest.py @@ -2,8 +2,9 @@ import random import urllib import urllib2 import re +import json -from util import hook, yaml +from util import hook @hook.command def suggest(inp): @@ -21,9 +22,9 @@ def suggest(inp): num = 0 url = 'http://google.com/complete/search?q=' + urllib.quote(inp, safe='') - json = urllib2.urlopen(url).read() - json = json[json.find('(') + 1: -1] - suggestions = yaml.load(json)[1] + page = urllib2.urlopen(url).read() + page_json = page.split('(', 1)[1][:-1] + suggestions = json.loads(page_json)[1] if not suggestions: return 'no suggestions found' if num: