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 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 calcResult(self): query = self.waeo.CreateQuery(self.inpt) raw_result = self.waeo.PerformQuery(query) content = wap.WolframAlphaQueryResult(raw_result) result = None resultImg = None if content.IsSuccess(): dataType = content.DataTypes()[0] if dataType == 'Math': for pod in content.Pods(): waPod = wap.Pod(pod) print waPod.Title()[0] pTitle = str(waPod.Title()[0]) if pTitle == 'Result' or 'result' in pTitle: waSubpod = wap.Subpod(waPod.Subpods()[0]) result = waSubpod.Plaintext()[0] elif 'MathematicalFunctionIdentity' in dataType: for pod in content.Pods(): waPod = wap.Pod(pod) if str(waPod.Title()[0]) == 'Decimal approximation': waSubpod = wap.Subpod(waPod.Subpods()[0]) result = waSubpod.Plaintext()[0] else: for pod in content.Pods(): waPod = wap.Pod(pod) solvedResults = ['Differential equation solution', 'Limit'] waPodTitle = str(waPod.Title()[0]) if 'integral' in waPodTitle or waPodTitle in solvedResults: waSubpod = wap.Subpod(waPod.Subpods()[0]) result = waSubpod.Plaintext()[0] rightIndex = result.rindex('=') + 2 result = result[rightIndex:] img = waSubpod.Img() resultImg = wap.scanbranches(img[0], 'src')[0] break elif 'Result' in waPodTitle: waSubpod = wap.Subpod(waPod.Subpods()[0]) result = waSubpod.Plaintext()[0] img = waSubpod.Img() resultImg = wap.scanbranches(img[0], 'src')[0] else: continue return result, resultImg
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 FC(data, show_gui=False): input = data server = 'http://api.wolframalpha.com/v2/query.jsp' with open('../../APPID_wolfram') as f: appid = f.readline().strip() # Need to further parse data; maybe? Nope! Unless we want timestamps ... :( 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] if(show_gui): 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] if(show_gui): print "-------------" print "img.src: " + src print "img.alt: " + alt if ( title.strip() == "Pod.title: Result" ): return alt; if(show_gui): print "\n" # Never got a result :( return "\0";
day = i["date"]["weekday"] + ", " + i["date"]["monthname"] + " " + i["date"]["day"] + ", " + i["date"]["year"] high = i["high"]["fahrenheit"] low = i["high"]["fahrenheit"] conditions = ["conditions"] loc = city.replace("_", " ") print "On %s, it will be %s in %s. The high will be %s degrees Fahrenheit. The low will be %s degrees Fahrenheit." % (day, conditions, loc, high, low) forecast.close() else: #assigning more wa variables queryStr = waeo.CreateQuery(question) wap.WolframAlphaQuery(queryStr, appid) %ssdddds result = waeo.PerformQuery(queryStr) result = wap.WolframAlphaQueryResult(result) #print wa results for pod in result.Pods(): waPod = wap.Pod(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 plaintext print "\n" question = ""
#!/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"
#!/usr/bin/env python # -*- coding: utf-8 -*- import wap server = 'http://api.wolframalpha.com/v2/query.jsp' appid = '28W43H-6P86G7XK79' input = 'What is Alzheimers?' waeo = wap.WolframAlphaEngine(appid, server) queryStr = waeo.CreateQuery(input) wap.WolframAlphaQuery(queryStr, appid) result = waeo.PerformQuery(queryStr) result = wap.WolframAlphaQueryResult(result) x = 0 print(result) for pod in result.Pods(): #if x < 2: waPod = wap.Pod(pod) for subpod in waPod.Subpods(): waSubpod = wap.Subpod(subpod) plaintext = waSubpod.Plaintext()[0] img = waSubpod.Img() alt = wap.scanbranches(img[0], 'alt')[0] print (alt) x = x + 1