def call_api(self, val): '''call API from Wolfram Alpha and return output''' server = 'http://api.wolframalpha.com/v2/query.jsp' appid = '6LA36U-7V45PGUA6E' input = val waeo = wap.WolframAlphaEngine(appid, server) queryStr = waeo.CreateQuery(val) wap.WolframAlphaQuery(queryStr, appid) result = waeo.PerformQuery(queryStr) result = wap.WolframAlphaQueryResult(result) for pod in result.Pods(): waPod = wap.Pod(pod) title = "Pod.title: " + waPod.Title()[0] self.ls_pod.append(waPod.Title()[0]) for subpod in waPod.Subpods(): waSubpod = wap.Subpod(subpod) plaintext = waSubpod.Plaintext()[0] img = waSubpod.Img() src = wap.scanbranches(img[0], 'src')[0] alt = wap.scanbranches(img[0], 'alt')[0] self.ls_src.append(src) self.ls_alt.append(alt) self.ls_src = map(str, self.ls_src) break return self.ls_pod
async def create_client(bot): """Create a new wolframalpha client object and store in volatile data.""" config = configurations.get(bot, __name__) client = wap.WolframAlphaEngine(config['api_key'], config['server']) client.ScanTimeout = config['scan_timeout'] client.PodTimeout = config['pod_timeout'] client.FormatTimeout = config['format_timeout'] data.add(bot, __name__, 'client', client, volatile=True) data.add(bot, __name__, 'uses', {}, volatile=True)
def __init__(self,input_string,assumption,appid,server,medical_test_wolram_query_flag,type_of_calculator,variable_input_dict ): self.medical_test_wolram_query_flag = medical_test_wolram_query_flag self.assumption = assumption self.input_string = input_string self.create_and_perform_wolfram_query = wap.WolframAlphaEngine(appid, server) self.query_str = self.create_and_perform_wolfram_query.CreateQuery(self.input_string) self.wolframalpha_query = wap.WolframAlphaQuery(self.query_str, appid) self.type_of_calculator = int(type_of_calculator) self.variable_input_dict = variable_input_dict
def running(): """ Method for actually running the display """ global img, queries for e in pygame.event.get(): if e.type is QUIT or (e.type is KEYDOWN and e.key == K_ESCAPE): return False elif e.type is KEYDOWN and e.key == K_SPACE: server = 'http://api.wolframalpha.com/v2/query.jsp' appid = 'RV3P54-H477JEA2XE' pos_queries = [ 'When is the next full moon?', 'What time is it in India?', 'How long is the flight from New York to Atlanta?', 'How far is DC to Anchorage?', 'Where is Emory University?', 'What is the current local time in Portland, Oregon?', ] rand_query = random.choice(pos_queries) queries.add(text='Query: ' + rand_query) waeo = wap.WolframAlphaEngine(appid, server) queryStr = waeo.CreateQuery(rand_query) result = waeo.PerformQuery(queryStr) result = wap.WolframAlphaQueryResult(result) p = result.Pods() try: waPod = wap.Pod(p[1]) waSubpod = wap.Subpod(waPod.Subpods()[0]) plaintext = waSubpod.Plaintext()[0] imgg = waSubpod.Img() alt = wap.scanbranches(imgg[0], 'alt')[0] queries.add(text=str(alt)) except IndexError: queries.add(text='No results found') rand_block(rr(10, 100)) screen = pygame.display.get_surface() screen.fill((0, 0, 0)) for screen_object in SCREEN_OBJECTS: screen_object.update() # draw the image screen.blit(img, (WIDTH - BUFFER - 200, HEIGHT - BUFFER - 200)) pygame.display.flip() return True
def checkConfiguration(self): #if configuration is proper set configured waeo = wap.WolframAlphaEngine(self.appid, self.host) waeq = wap.WolframAlphaQuery("pi", self.appid) waeq.ToURL() try: waeqr = wap.WolframAlphaQueryResult(waeo.PerformQuery(waeq.Query)) if (waeqr.IsSuccess()): self.waeo = waeo self.configured = True else: self.configured = False except Exception: print("connection failure")
def getFromWolfram(): inputsta = 'y"+y=0' appid = '4WKYHL-AWUQL4GWA3' # Use your app id waeo = wap.WolframAlphaEngine(appid, 'http://api.wolframalpha.com/v2/query?') waeq = wap.WolframAlphaQuery(inputsta, appid) waeq.ScanTimeout = '3.0' waeq.AddPodState('DifferentialEquationSolution__Step-by-step solution') waeq.Async = False waeq.ToURL() # After configuring the waeq must call ToURL() #print(waeq.Query) result = waeo.PerformQuery(waeq.Query) # result is in xml format return result
def enInit(self): com = self.get('endroid.plugins.command') try: self.api_key = self.vars['api_key'] self.server = self.vars.get('server', WOLFRAM_API_SERVER_DEFAULT) com.register_muc( lambda msg, arg: self.handle_command(msg, arg, True), 'compute') com.register_chat(self.handle_command, 'compute') self.waeo = wap.WolframAlphaEngine(self.api_key, self.server) except KeyError: logging.error( "ERROR: Compute: There is no API key set in config! Set 'api_key' variable" " in section '[Plugin:endroid.plugins.compute]'. Aborting plugin load." ) raise PluginInitError("Aborted plugin initialization")
def __init__(self, query, assumption=None, state=None, width=WIDTH, maxwidth=MAX_WIDTH, plotwidth=PLOT_WIDTH, magnification=MAGNIFICATION): engine = wap.WolframAlphaEngine(APP_ID, SERVER) engine.Width = width engine.MaxWidth = maxwidth engine.PlotWidth = plotwidth engine.Mag = magnification queryObj = engine.CreateQuery(query) if assumption: queryObj.AddAssumption(assumption.input) if state: queryObj.AddPodState(state) queryResult = engine.PerformQuery(queryObj) self.__result = wap.WolframAlphaQueryResult(queryResult)
def get_answer_from_wolfram_alpha(self, command): #url = 'http://preview.wolframalpha.com/api/v1/query.jsp' #url = 'http://preview.wolframalpha.com/api/v1/validatequery.jsp' #url = 'http://api.wolframalpha.com/v1/query.jsp' #url = 'http://api.wolframalpha.com/v1/validatequery.jsp' server = 'http://api.wolframalpha.com/v1/query.jsp' appid = 'PGRY4P-6AGPPP4TXE' scantimeout = '3.0' podtimeout = '4.0' formattimeout = '8.0' async = 'False' waeq = wap.WolframAlphaEngine(appid, server) waeq.ScanTimeout = scantimeout waeq.PodTimeout = podtimeout waeq.FormatTimeout = formattimeout waeq.Async = async
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. '''An example that provides a python interface to the wap library''' __author__ = '*****@*****.**' __version__ = '1.1-devel' import wap import urllib #url = 'http://preview.wolframalpha.com/api/v1/query.jsp' #url = 'http://preview.wolframalpha.com/api/v1/validatequery.jsp' #url = 'http://api.wolframalpha.com/v1/query.jsp' #url = 'http://api.wolframalpha.com/v1/validatequery.jsp' server = 'http://api.wolframalpha.com/v1/query.jsp' appid = 'XXXX' input = 'who are you?' waeo = wap.WolframAlphaEngine(appid, server) query = waeo.CreateQuery(input) result = waeo.PerformQuery(query) waeqr = wap.WolframAlphaQueryResult(result) jsonresult = waeqr.JsonResult() print jsonresult
from flask import Flask, request, jsonify import wap application = Flask(__name__) API_URL = 'http://api.wolframalpha.com/v2/query.jsp' WA_APP_ID = 'T4V4XY-82RGQ926U9' waeo = wap.WolframAlphaEngine(WA_APP_ID, API_URL) def get_results(equation): queryStr = waeo.CreateQuery(equation) wap.WolframAlphaQuery(queryStr, WA_APP_ID) result = waeo.PerformQuery(queryStr) result = wap.WolframAlphaQueryResult(result) data = [] answer = [] for pod in result.Pods(): waPod = wap.Pod(pod) title = "Pod.title: " + waPod.Title()[0] print title for subpod in waPod.Subpods(): waSubpod = wap.Subpod(subpod) plaintext = waSubpod.Plaintext()[0] img = waSubpod.Img() src = wap.scanbranches(img[0], 'src')[0] alt = wap.scanbranches(img[0], 'alt')[0] print "-------------"
def __init__(self, input): self.waeo = wap.WolframAlphaEngine(appid, server) self.inpt = input
while 1: qBotLib.resetBotParts(); question=raw_input('\n> '); if qBotLib.isQuestionProfane(question)==1: print qBotLib.proFaneMsg_array[random.randint(0,1)]; elif qBotLib.isQuestionOverriden(question)!=-1: print qBotLib.overridenQAns[qBotLib.isQuestionOverriden(question)]; else: waeo = wap.WolframAlphaEngine(qBotLib.appid, qBotLib.server); queryStr = waeo.CreateQuery(question); wap.WolframAlphaQuery(queryStr, qBotLib.appid); result = waeo.PerformQuery(queryStr); result = wap.WolframAlphaQueryResult(result); for pod in result.Pods(): waPod = wap.Pod(pod); title = waPod.Title()[0]; if title == "Result": qBotLib.findAnswer(waPod); qBotLib.updateNoAnsFlag(1); break; #Check if we have any reply from Knowledge engine if qBotLib.noAns!=1:
import sys import os from time import sleep from openpyxl import Workbook sys.path.insert(0, 'lib/wolfram/Python_Binding_1_1') import wap wolfram_key = appid = os.environ['WOLFRAM_KEY'] query_url = 'http://api.wolframalpha.com/v2/query.jsp' job_name = raw_input("What type of job are you looking for (singular)? ") job_location_name = raw_input("Where would you like to work? ") engine = wap.WolframAlphaEngine(wolfram_key, query_url) query = engine.CreateQuery('Average salary for ' + job_name + ' in ' + job_location_name) wap.WolframAlphaQuery(query, query_url) engine_query = engine.PerformQuery(query) result = wap.WolframAlphaQueryResult(engine_query) if result.IsSuccess(): print('Success!') else: print('Failure!') exit(1) for pod in result.Pods(): waPod = wap.Pod(pod) title = waPod.Title()[0]