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


Python wolframalpha.Client方法代码示例

本文整理汇总了Python中wolframalpha.Client方法的典型用法代码示例。如果您正苦于以下问题:Python wolframalpha.Client方法的具体用法?Python wolframalpha.Client怎么用?Python wolframalpha.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wolframalpha的用法示例。


在下文中一共展示了wolframalpha.Client方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def handle(self, text, mic):
	    app_id = self.profile['keys']['WOLFRAMALPHA']
	    client = wolframalpha.Client(app_id)

	    query = client.query(text)
	    if len(query.pods) > 0:
		texts = ""
		pod = query.pods[1]
		if pod.text:
		    texts = pod.text
		else:
		    texts = "I can not find anything"

		mic.say(texts.replace("|",""))
	    else:
		mic.say("Sorry, Could you be more specific?.") 
开发者ID:nexhero,项目名称:wolframalpha_jasper,代码行数:18,代码来源:knowledged.py

示例2: search_wolfram

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def search_wolfram(query, api_key):
    '''Search wolframalpha'''
    client = wolframalpha.Client(api_key)
    # Santize query
    res = client.query(query)
    try:
        next_result = next(res.results).text
        if next_result:
            # Sanitze result
            log.debug("Sanitized wolfram result is {0}".format(next_result))
            return next_result
        else:
            return False
    except StopIteration:
        log.error("StopIteration raised with wolfram query {0}".format(
            query
        ))
        return False
    except AttributeError:
        return False 
开发者ID:ironman5366,项目名称:W.I.L.L,代码行数:22,代码来源:search.py

示例3: ask_wolfram

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def ask_wolfram(self, question):
        client = wolframalpha.Client(self.key)
        res = client.query(question)
        if len(res.pods) > 0:
            pod = res.pods[1]
            if pod.text:
                texts = pod.text
            else:
                raise APIError('Wolfram API failed.')
            # to skip ascii character in case of error
            texts = texts.encode('ascii', 'ignore')
            return texts
        else:
            raise APIError('Wolfram API failed.') 
开发者ID:namco1992,项目名称:voicetools,代码行数:16,代码来源:api.py

示例4: tts

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def tts(self, tex, lan='zh', ctp=1,
            cuid=None, spd=5, pit=5, vol=5, per=0):
        """Constructs and sends an Text To Speech request.

        Args:
            tex: The text for conversion.
            lan:(optional) language, default is 'zh'.
            ctp:(optional) Client type, default is 1.
            cuid:(optional) Unique identification of user, default is MAC address.
            spd:(optional) speed, range 0-9, default is 5.
            pit:(optional) pitch, range 0-9, default is 5.
            vol:(optional) volume, range 0-9, default is 5.
            per:(optional) voice of male or female, default is 0 for female voice.
        Returns:
            A binary string of MP3 format audio.
        Raises:
            ValueError
            VerifyError
            APIError
        """
        params = {
            'tex': tex,
            'lan': lan,
            'tok': self.token,
            'ctp': ctp,
            'cuid': cuid or self.cuid,
            'spd': spd,
            'pit': pit,
            'vol': vol,
            'per': per
        }
        return baiduclient.tts(params) 
开发者ID:namco1992,项目名称:voicetools,代码行数:34,代码来源:api.py

示例5: __init__

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def __init__(self, bot, config):
        self.bot = bot
        self.session = aiohttp.ClientSession(loop=bot.loop)
        self.config = config
        self.wolframClient = wolframalpha.Client(self.config.get_config_value('wolfram', 'WOLFRAM_API_TOKEN'))
        self.help_dict = self.config.get_help_json() 
开发者ID:CSSS,项目名称:wall_e,代码行数:8,代码来源:misc.py

示例6: wolframLookUp

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def wolframLookUp(a_string):
	client = wolframalpha.Client(keyring.get_password('wolfram','app_id'))
	pattern = re.compile('([^\s\w]|_)+')
	b_string = re.sub(pattern, '', a_string)
	phrase=b_string
	pattern = re.compile("\\b(what|is)\\W", re.I)
	phrase_noise_removed = [pattern.sub("", phrase)] 
	try:
		res= client.query(a_string)
		return next(res.results).text
	except:
		return "Sorry" 
开发者ID:schollz,项目名称:rpi_ai,代码行数:14,代码来源:temporal_lobe.py

示例7: matrix_message

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def matrix_message(self, bot, room, event):
        args = event.body.split()
        if len(args) == 3:
            if args[1] == "appid":
                bot.must_be_owner(event)
                self.app_id = args[2]
                bot.save_settings()
                await bot.send_text(room, 'App id set')
                print('Appid', self.app_id)
                return

        if len(args) > 1:
            if self.app_id == '':
                await bot.send_text(room, 'Please get and set a appid: https://products.wolframalpha.com/simple-api/documentation/')
                return

            query = event.body[len(args[0])+1:]
            client = wolframalpha.Client(self.app_id)
            answer = query + ': '
            try:
                res = client.query(query)
                for pod in res.results:
                    for sub in pod.subpods:
                        print(sub)
                        answer += str(sub.plaintext) + "\n"
            except Exception as exc:
                answer = str(exc)

            await bot.send_text(room, answer)
        else:
            await bot.send_text(room, 'Usage: !wa <query>') 
开发者ID:vranki,项目名称:hemppa,代码行数:33,代码来源:wa.py

示例8: _initialise

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def _initialise(bot):
    apikey = bot.get_config_option("wolframalpha-apikey")
    if apikey:
        _internal["client"] = wolframalpha.Client(apikey)
        plugins.register_user_command(["ask"])
    else:
        logger.error('WOLFRAMALPHA: config["wolframalpha-apikey"] required') 
开发者ID:hangoutsbot,项目名称:hangoutsbot,代码行数:9,代码来源:wolframalpha.py

示例9: activate

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def activate(self):
        super().activate()
        self.client = wolframalpha.Client(self.config['WA_TOKEN']) 
开发者ID:coala,项目名称:corobo,代码行数:5,代码来源:wolfram_alpha.py

示例10: client

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def client(API_key):
    return wolframalpha.Client(API_key) 
开发者ID:jaraco,项目名称:wolframalpha,代码行数:4,代码来源:conftest.py

示例11: wa

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def wa(client, event, channel, nick, rest):
    """
    A free-text query resolver by Wolfram|Alpha. Returns the first
    result, if available.
    """
    client = wolframalpha.Client(pmxbot.config['Wolfram|Alpha API key'])
    res = client.query(rest)
    return next(res.results).text 
开发者ID:jaraco,项目名称:wolframalpha,代码行数:10,代码来源:pmxbot.py

示例12: test_invalid_app_id

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def test_invalid_app_id():
    client = wolframalpha.Client('abcdefg')
    with pytest.raises(Exception):
        client.query('30 deg C in deg F') 
开发者ID:jaraco,项目名称:wolframalpha,代码行数:6,代码来源:test_client.py

示例13: __init__

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def __init__(self, app_id):
		logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')

		self.wolfram_client = wolframalpha.Client(app_id)
		logging.info("connected to wolfram") 
开发者ID:plutov,项目名称:bot,代码行数:7,代码来源:dataprovider.py

示例14: execute

# 需要导入模块: import wolframalpha [as 别名]
# 或者: from wolframalpha import Client [as 别名]
def execute(cls, slack_wrapper, args, timestamp, channel_id, user_id, user_is_admin):
        """Execute the Ask command."""
        app_id = handler_factory.botserver.get_config_option("wolfram_app_id")

        verbose = (args[0] if args else "") == "-v"

        if app_id:
            try:
                if verbose:
                    question = " ".join(args[1:])
                else:
                    question = " ".join(args)

                client = wolframalpha.Client(app_id)
                res = client.query(question)

                answer = ""

                if verbose:
                    for pod in res.pods:
                        for subpod in pod.subpods:
                            if "plaintext" in subpod.keys() and subpod["plaintext"]:
                                answer += "```\n"
                                answer += subpod.plaintext[:512] + "\n"
                                answer += "```\n"
                                if len(subpod.plaintext) > 512:
                                    answer += "*shortened*"
                else:
                    answer = next(res.results, None)

                    if answer:
                        if len(answer.text) > 2048:
                            answer = answer.text[:2048] + "*shortened*"
                        else:
                            answer = answer.text

                slack_wrapper.post_message(channel_id, answer)
            except Exception as ex:
                if "Invalid appid" in str(ex):
                    response = "Wolfram Alpha app id doesn't seem to be correct (or api is choking)..."
                else:
                    response = "Wolfram Alpha doesn't seem to understand you :("

                slack_wrapper.post_message(channel_id, response)
        else:
            response = "It seems you have no valid wolfram alpha app id. Contact an admin about this..."

            slack_wrapper.post_message(channel_id, response) 
开发者ID:OpenToAllCTF,项目名称:OTA-Challenge-Bot,代码行数:50,代码来源:wolfram_handler.py


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