当前位置: 首页>>代码示例>>Python>>正文


Python web.json函数代码示例

本文整理汇总了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)
开发者ID:SmallJoker,项目名称:minetestbot-modules,代码行数:7,代码来源:search.py

示例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"]
            )
        )
开发者ID:goavki,项目名称:phenny,代码行数:25,代码来源:wuvt.py

示例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)
开发者ID:BlackRobeRising,项目名称:jenni,代码行数:30,代码来源:movie.py

示例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
开发者ID:Kitsueki,项目名称:jenni,代码行数:7,代码来源:translate.py

示例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)
开发者ID:embolalia,项目名称:jenni,代码行数:8,代码来源:search.py

示例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
开发者ID:Kitsueki,项目名称:jenni,代码行数:8,代码来源:translate.py

示例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)
开发者ID:KaiCode2,项目名称:phenny,代码行数:8,代码来源:search.py

示例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)
开发者ID:btelle,项目名称:shana2,代码行数:9,代码来源:search.py

示例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)
开发者ID:embolalia,项目名称:phenny,代码行数:9,代码来源:search.py

示例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
开发者ID:endenizen,项目名称:torp,代码行数:9,代码来源:translate.py

示例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
开发者ID:endenizen,项目名称:torp,代码行数:10,代码来源:translate.py

示例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)
开发者ID:Mithorium,项目名称:Mithnet,代码行数:11,代码来源:facebook.py

示例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)
开发者ID:AaronCrosley,项目名称:phenny,代码行数:11,代码来源:search.py

示例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))
开发者ID:chravikishore,项目名称:os_projectbot,代码行数:11,代码来源:github.py

示例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)
开发者ID:sirpercival,项目名称:eiko,代码行数:11,代码来源:search.py


注:本文中的web.json函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。