Python wolframalpha.Client() Examples
The following are 14
code examples of wolframalpha.Client().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wolframalpha
, or try the search function
.
Example #1
Source File: knowledged.py From wolframalpha_jasper with GNU General Public License v2.0 | 6 votes |
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?.")
Example #2
Source File: search.py From W.I.L.L with MIT License | 6 votes |
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
Example #3
Source File: api.py From voicetools with Apache License 2.0 | 5 votes |
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.')
Example #4
Source File: api.py From voicetools with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: misc.py From wall_e with GNU General Public License v3.0 | 5 votes |
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()
Example #6
Source File: temporal_lobe.py From rpi_ai with MIT License | 5 votes |
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"
Example #7
Source File: wa.py From hemppa with GNU General Public License v3.0 | 5 votes |
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>')
Example #8
Source File: wolframalpha.py From hangoutsbot with GNU Affero General Public License v3.0 | 5 votes |
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')
Example #9
Source File: wolfram_alpha.py From corobo with MIT License | 5 votes |
def activate(self): super().activate() self.client = wolframalpha.Client(self.config['WA_TOKEN'])
Example #10
Source File: conftest.py From wolframalpha with MIT License | 5 votes |
def client(API_key): return wolframalpha.Client(API_key)
Example #11
Source File: pmxbot.py From wolframalpha with MIT License | 5 votes |
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
Example #12
Source File: test_client.py From wolframalpha with MIT License | 5 votes |
def test_invalid_app_id(): client = wolframalpha.Client('abcdefg') with pytest.raises(Exception): client.query('30 deg C in deg F')
Example #13
Source File: dataprovider.py From bot with MIT License | 5 votes |
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")
Example #14
Source File: wolfram_handler.py From OTA-Challenge-Bot with MIT License | 4 votes |
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)