def query(Allkey): Allkey = Allkey.encode("utf-8") key = ' '.join(Allkey.split(" ")[1:]) results = [] if key: if Allkey.endswith(' '): q = google.googletranslate(key) if not q: q = key que = client.query(q) for pod in que.pods: if pod.text and pod.text != 'nun': res = {} res["Title"] = pod.text res["IcoPath"] = './icon.png' results.append(res) return json.dumps(results) else: url = 'http://www.wolframalpha.com/input/autocomplete.jsp?qr=0&i='+key html = requests(url) html = json.loads(html) for i in html["results"]: res = {} res["Title"] = i["input"] try: res["SubTitle"] = i["description"] except Exception, e: print e res["IcoPath"] = './icon.png' results.append(res) return json.dumps(results)
# -*- coding: utf-8 -*- import wolframalpha,google client = wolframalpha.Client('7UW6LK-YW9T8YPYAG') q = google.googletranslate('谁是毛泽东') print q res = client.query('30 deg C in deg F') #res = client.query('who is maozedong') results = list(res.results) for pod in res.pods: print pod.text for i in results: print i.text print next(que.results).text