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
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 "-------------" print "img.src: " + src image = "img.src: " + src data.append(src) answer.append(plaintext) print "img.alt: " + alt print "\n" return data, answer
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 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 getResult(self, query): #method to get result if (self.isConfigured()): try: waeq = wap.WolframAlphaQuery(query, self.appid) waeq.Async = False waeq.ToURL() result = self.waeo.PerformQuery(waeq.Query) waeqr = wap.WolframAlphaQueryResult(result) for pod in waeqr.Pods(): waep = wap.Pod(pod) if (waep.PodStates()[0][1][2][1] == 'Step-by-step solution' ): self.stepinput = waep.PodStates()[0][1][1][1] break waeq = wap.WolframAlphaQuery(query, self.appid) waeq.AddPodState(self.stepinput) waeq.Async = False waeq.ToURL() result = self.waeo.PerformQuery(waeq.Query) f = open(query + '.txt', 'w') f.write(result) f.close() except Exception: print("connection problem")
scantimeout = '3.0' podtimeout = '4.0' formattimeout = '8.0' async = 'True' waeo = wap.WolframAlphaEngine(appid, server) waeo.ScanTimeout = scantimeout waeo.PodTimeout = podtimeout waeo.FormatTimeout = formattimeout waeo.Async = async query = waeo.CreateQuery(input) waeq = wap.WolframAlphaQuery(input, appid) waeq.ScanTimeout = scantimeout waeq.PodTimeout = podtimeout waeq.FormatTimeout = formattimeout waeq.Async = async waeq.ToURL() query = waeq.Query result = waeo.PerformQuery(query) #print result soup = BeautifulSoup(result) print '\n', "**********************************************", '\n' res = soup.findAll('assumption') #print res for r in res:
#!/usr/bin/env python # -*- coding: utf-8 -*- import wap server = 'http://api.wolframalpha.com/v2/query.jsp' appid = 'XXXX' input = 'pi' waeo = wap.WolframAlphaEngine(appid, server) queryStr = waeo.CreateQuery(input) 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] 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 "-------------" print "img.src: " + src print "img.alt: " + alt print "\n"
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: print qBotLib.preDefinedMsg_array[random.randint(0,1)];
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] print title if title == 'Result': for subpod in waPod.Subpods():