use py2.6 json module instead of yaml as a json decoder
This commit is contained in:
parent
f204e42197
commit
90cb5bf47d
|
@ -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'], ''))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue