• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python web.json函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中web.json函数的典型用法代码示例。如果您正苦于以下问题:Python json函数的具体用法?Python json怎么用?Python json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了json函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: f_list_git_pull_requests

def f_list_git_pull_requests(phenny, input):
    prList = web.json(web.get("http://github.com/api/v2/json/pulls/%s/open" % phenny.config.github_project))
    pulls = prList["pulls"]
    if len(pulls) == 0:
        phenny.say("There are no open pull requests in %s" % phenny.config.github_project)
    else:
        phenny.say("%s open pull request%s:" % (len(pulls), "s" if len(pulls) != 1 else ""))
        for issue in pulls:
            title = issue["title"][:60]
            if len(issue["title"]) > 60: title += "..."
            phenny.say("%s: %s %s" % (issue["user"]["login"], title, shorten(issue["html_url"])))
开发者ID:chravikishore,项目名称:os_projectbot,代码行数:11,代码来源:github.py


示例17: btc

def btc(phenny, input):
	"""Get current Bitcoin price"""
	data, sc = web.get('https://blockchain.info/ticker')
	data = str(data, 'utf-8')
	data = web.json(data)
	if input.group(2):
		currency = input.group(2).strip().upper()
	else:
		currency = 'USD'
	if not currency in data.keys():
		return phenny.reply('Unknown currency. Supported currencies: ' + ', '.join(data.keys()))
	phenny.say('1 BTC = %.4f %s' % (data[currency]['15m'], data[currency]['symbol']))
开发者ID:jamestait,项目名称:minetestbot-modules,代码行数:12,代码来源:shortutils.py


示例18: mod

def mod(phenny, input):
    uri = "http://nimg.pf-control.de/MTstuff/modSearchAPI.php?q="
    text, sc = web.get(uri + input.group(2))
    text = str(text, "utf-8")
    data = web.json(text)
    answer = ""
    if "error" in data:
        answer = data["error"]
    else:
        answer = data["title"] + " by " + data["author"] + " - " + data["link"]

    phenny.reply(answer)
开发者ID:asl97,项目名称:minetestbot-modules,代码行数:12,代码来源:modsearch.py


示例19: gitrepo

def gitrepo(torp, input):
  q = input.group(2)
  uri = 'http://github.com/api/v2/json/repos/show/%s' % q
  bytes = web.get(uri)
  result = web.json(bytes)
  print result
  if result.has_key('error'):
    torp.say(result['error'])
  elif result.has_key('repository'):
    repo = result['repository']
    msg = '%s: %s. (%dw, %df) %s' % (repo['name'], repo['description'], repo['watchers'], repo['forks'], repo['url'])
    print msg
    torp.say(msg)
开发者ID:endenizen,项目名称:torp,代码行数:13,代码来源:github.py


示例20: server

def server(phenny, input):
    arg = input.group(2)
    if not arg:
        cmds = [(by_random, "")]
    else:
        arg = arg.strip().split(" ")
        cmds = []
        for a in arg:
            choicefunc = None
            for mname in compare_methods:
              if a.lower().startswith(mname + ":"):
                choicefunc = compare_methods[mname]
                carg = a[len(mname + ":"):]
                break
            if a.lower() == "random":
                choicefunc = by_random
                carg = ""
            elif not choicefunc:
                choicefunc = compare_methods[default_method]
                carg = a
            cmds.append((choicefunc, carg))

    text, sc = web.get("http://servers.minetest.net/list")
    text = str(text, 'utf-8')
    server_list = web.json(text)["list"]
    prep_table = server_list
    for i in range(0, len(cmds)):
        choicefunc, carg = cmds[i]
        choices = choicefunc(prep_table, carg)
        if len(choices) == 0:
            return phenny.reply("No results")
        prep_table = list(prep_table[c] for c in choices)

    choice = prep_table[0]
    name = choice["name"]
    address = choice["address"]
    if choice["port"] != 30000:
        if ':' in address: # IPv6
            address = "[" + address + "]"
        address += ":" + str(choice["port"])
    clients = choice["clients"]
    if "gameid" in choice:
        version = choice["version"] + " / " + choice["gameid"]
    else:
        version = choice["version"]
    ping = int(choice["ping"] * 1000)
    clients_max = choice["clients_max"]
    clients_avg = choice["pop_v"]
    clients_top = choice["clients_top"]

    phenny.reply("%s | %s | Clients: %d/%d, %d/%d | Version: %s | Ping: %dms" % (name, address, clients, clients_max, clients_avg, clients_top, version, ping))
开发者ID:SmallJoker,项目名称:minetestbot-modules,代码行数:51,代码来源:server.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python web.listget函数代码示例发布时间:2022-05-26
下一篇:
Python web.internalerror函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap