Created endpoint to communicate with the wolfram alpha spoken api
parent
b1eba07e8e
commit
fabcba8c54
|
@ -20,6 +20,7 @@ from .endpoints.device_subscription import DeviceSubscriptionEndpoint
|
|||
from .endpoints.google_stt import GoogleSTTEndpoint
|
||||
from .endpoints.open_weather_map import OpenWeatherMapEndpoint
|
||||
from .endpoints.wolfram_alpha import WolframAlphaEndpoint
|
||||
from .endpoints.wolfram_alpha_spoken import WolframAlphaSpokenEndpoint
|
||||
|
||||
public = Flask(__name__)
|
||||
public.config.from_object(get_base_config())
|
||||
|
@ -114,3 +115,8 @@ public.add_url_rule(
|
|||
view_func=DeviceRefreshTokenEndpoint.as_view('refresh_token_api'),
|
||||
methods=['GET']
|
||||
)
|
||||
public.add_url_rule(
|
||||
'/wolframAlphaSpoken',
|
||||
view_func=WolframAlphaSpokenEndpoint.as_view('wolfram_alpha_spoken_api'),
|
||||
methods=['GET']
|
||||
)
|
||||
|
|
|
@ -3,6 +3,7 @@ from http import HTTPStatus
|
|||
|
||||
import requests
|
||||
from flask import Response
|
||||
|
||||
from selene.api import SeleneEndpoint
|
||||
|
||||
|
||||
|
@ -17,6 +18,6 @@ class WolframAlphaEndpoint(SeleneEndpoint):
|
|||
input = self.request.args.get('input')
|
||||
if input:
|
||||
params = dict(appid=self.wolfram_alpha_key, input=input)
|
||||
response = requests.get(self.wolfram_alpha_url, params=params)
|
||||
response = requests.get(self.wolfram_alpha_url + '/v2/query', params=params)
|
||||
if response.status_code == HTTPStatus.OK:
|
||||
return Response(response.content, mimetype='text/xml')
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import os
|
||||
from http import HTTPStatus
|
||||
|
||||
import requests
|
||||
|
||||
from selene.api import SeleneEndpoint
|
||||
|
||||
|
||||
class WolframAlphaSpokenEndpoint(SeleneEndpoint):
|
||||
"""Endpoint to communicate with the Wolfram Alpha Spoken API"""
|
||||
|
||||
def __init__(self):
|
||||
super(WolframAlphaSpokenEndpoint, self).__init__()
|
||||
self.wolfram_alpha_key = os.environ['WOLFRAM_ALPHA_KEY']
|
||||
self.wolfram_alpha_url = os.environ['WOLFRAM_ALPHA_URL']
|
||||
|
||||
def get(self):
|
||||
params = dict(self.request.args)
|
||||
params['appid'] = self.wolfram_alpha_key
|
||||
response = requests.get(self.wolfram_alpha_url + '/v1/spoken', params=params)
|
||||
response = (response.text, HTTPStatus.OK) if response.status_code == HTTPStatus.OK else ('', response.status_code)
|
||||
return response
|
Loading…
Reference in New Issue