本文整理汇总了Python中web.json函数的典型用法代码示例。如果您正苦于以下问题:Python json函数的具体用法?Python json怎么用?Python json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: google_ajax
def google_ajax(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.urlencode(query)
data, sc = web.get(uri + args)
data = str(data, 'utf-8')
return web.json(data)
示例2: wuvt
def wuvt(phenny, input):
""".wuvt - Find out what is currently playing on the radio station WUVT."""
try:
data = web.get("https://www.wuvt.vt.edu/playlists/latest_track", headers={"Accept": "application/json"})
trackinfo = web.json(data)
except:
raise GrumbleError("Failed to fetch current track from WUVT")
if "listeners" in trackinfo:
phenny.say(
'{dj} is currently playing "{title}" by {artist} with '
"{listeners:d} online listeners".format(
dj=trackinfo["dj"],
title=trackinfo["title"],
artist=trackinfo["artist"],
listeners=trackinfo["listeners"],
)
)
else:
phenny.say(
'{dj} is currently playing "{title}" by {artist}'.format(
dj=trackinfo["dj"], title=trackinfo["title"], artist=trackinfo["artist"]
)
)
示例3: movie
def movie(jenni, input):
""".imdb movie/show title -- displays information about a production"""
if not input.group(2):
return
word = input.group(2).rstrip()
word = word.replace(" ", "+")
uri = "http://www.imdbapi.com/?t=" + word
uri = uri.encode('utf-8')
page = web.get(uri)
data = web.json(page)
if data['Response'] == 'False':
if 'Error' in data:
message = '[MOVIE] %s' % data['Error']
else:
jenni.debug('movie',
'Got an error from the imdb api,\
search phrase was %s' %
word, 'warning')
jenni.debug('movie', str(data), 'warning')
message = '[MOVIE] Got an error from imdbapi'
else:
message = '[MOVIE] Title: ' + data['Title'] + \
' | Year: ' + data['Year'] + \
' | Rating: ' + data['imdbRating'] + \
' | Genre: ' + data['Genre'] + \
' | IMDB Link: http://imdb.com/title/' + data['imdbID']
jenni.say(message)
示例4: detect
def detect(text):
uri = 'http://ajax.googleapis.com/ajax/services/language/detect'
q = urllib.quote(text)
bytes = web.get(uri + '?q=' + q + '&v=1.0')
result = web.json(bytes)
try: return result['responseData']['language']
except Exception: return None
示例5: google_ajax
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
if isinstance(query, unicode):
query = query.encode('utf-8')
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
args = '?v=1.0&safe=off&q=' + web.quote(query)
bytes = web.get(uri + args)
return web.json(bytes)
示例6: translate
def translate(text, input, output):
uri = 'http://ajax.googleapis.com/ajax/services/language/translate'
q = urllib.quote(text)
pair = input + '%7C' + output
bytes = web.get(uri + '?q=' + q + '&v=1.0&langpair=' + pair)
result = web.json(bytes)
try: return result['responseData']['translatedText'].encode('cp1252')
except Exception: return None
示例7: google_ajax
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
if isinstance(query, str):
query = query.encode('utf-8')
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
args = '?v=1.0&safe=off&q=' + web.quote(query)
bytes = web.get(uri + args, headers={'Referer': 'https://github.com/sbp/phenny'})
return web.json(bytes)
示例8: search
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.parse.quote(query.encode('utf-8'))
handler = web.urllib.request._urlopener
web.urllib.request._urlopener = Grab()
bytes = web.get(uri + args).decode('utf-8')
web.urllib.request._urlopener = handler
return web.json(bytes)
示例9: google_ajax
def google_ajax(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)
handler = web.urllib._urlopener
web.urllib._urlopener = Grab()
bytes = web.get(uri + args)
web.urllib._urlopener = handler
return web.json(bytes)
示例10: detect
def detect(text):
uri = "http://ajax.googleapis.com/ajax/services/language/detect"
q = urllib.quote(text)
bytes = web.get(uri + "?q=" + q + "&v=1.0")
result = web.json(bytes)
try:
return result["responseData"]["language"]
except Exception:
return None
示例11: translate
def translate(text, input, output):
uri = "http://ajax.googleapis.com/ajax/services/language/translate"
q = urllib.quote(text)
pair = input + "%7C" + output
bytes = web.get(uri + "?q=" + q + "&v=1.0&langpair=" + pair)
result = web.json(bytes)
try:
return result["responseData"]["translatedText"].encode("cp1252")
except Exception:
return None
示例12: search
def search(query):
"""Search using AjaxSearch, and return its JSON."""
if query.startswith('me') or query.startswith('514719084') or query.startswith('michael.fu'):
return False
uri = 'https://graph.facebook.com/'
args = web.urllib.quote(query.encode('utf-8')) + '?access_token=245062872172460|bc67e3f85e6ec52109d9f7ca.1-514719084|jkDwqgaoEbjuH5UxSXJIq68Hps8'
handler = web.urllib._urlopener
web.urllib._urlopener = Grab()
bytes = web.get(uri + args)
web.urllib._urlopener = handler
return web.json(bytes)
示例13: google_ajax
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
if isinstance(query, str):
query = query.encode('utf-8')
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
args = '?v=1.0&safe=off&q=' + web.quote(query)
handler = web.urllib.request._urlopener
web.urllib.request._urlopener = Grab()
bytes = web.get(uri + args)
web.urllib.request._urlopener = handler
return web.json(bytes)
示例14: _find_github_file
def _find_github_file(phenny, branch, fname):
bag = web.json(web.get("https://github.com/api/v2/json/blob/all/%s/%s" % (phenny.config.github_project, branch)))["blobs"]
outlist = [f for f in bag.keys() if re.search(fname.lower(), f.lower())]
outlist.sort()
if outlist:
phenny.say ("Found %s matching file(s) in the %s branch. First %s are:" % (len(outlist), branch, min(5, len(outlist))))
for found in outlist[:5]:
fnd = found.strip("/")
url = "https://github.com/%s/tree/%s/%s" % (phenny.config.github_project, branch, fnd)
url = shorten(url)
phenny.say("%s %s" % (found, url))
示例15: google_ajax
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
if isinstance(query, unicode):
query = query.encode("utf-8")
uri = "http://ajax.googleapis.com/ajax/services/search/web"
args = "?v=1.0&safe=off&q=" + web.urllib.quote(query)
handler = web.urllib._urlopener
web.urllib._urlopener = Grab()
bytes = web.get(uri + args)
web.urllib._urlopener = handler
return web.json(bytes)