This repository has been archived on 2023-06-09. You can view files and clone it, but cannot push or open issues or pull requests.
jarvis-server/jarvis/utils/fallbacks/wolframalpha/wa_client.py

23 lines
581 B
Python
Raw Normal View History

2021-09-14 10:49:09 +02:00
import urllib.parse
import requests
from jarvis.utils import config_utils
def ask(sentence):
query = urllib.parse.quote_plus(sentence)
query_url = f"https://api.wolframalpha.com/v2/query?" \
f"appid={config_utils.get_in_secret('WOLFRAM_APP_ID')}" \
f"&input={query}" \
f"&format=plaintext" \
f"&output=json"
r = requests.get(query_url).json()
if r['queryresult']['success']:
data = r["queryresult"]["pods"][1]["subpods"][0]
return data['plaintext']
else:
return None