From 8141b4227780faddc9672041bda60d84206b8422 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Tue, 17 Oct 2017 18:24:07 +0100 Subject: make speech project public --- wolfram/lat.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 wolfram/lat.py (limited to 'wolfram/lat.py') diff --git a/wolfram/lat.py b/wolfram/lat.py new file mode 100644 index 0000000..92f31d1 --- /dev/null +++ b/wolfram/lat.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import requests +from urllib import quote_plus +import xml.etree.ElementTree as ET + +appid = 'U6E8UV-AP3QJAT6RK' + +def get_plaintext_query(latex): + r = requests.get('http://api.wolframalpha.com/v2/query?input=%s&appid=%s' % (quote_plus(latex), appid)) + root = ET.fromstring(r.text.encode('utf8')) + + for pod in root: + if pod.attrib.get('title', '') in ['Decimal approximation', 'Definite integral']: + subpod = pod.find('subpod') + result = subpod.find('plaintext').text + + if pod.attrib.get('title', '') == 'Definite integral': + return result.split('~~')[1] + else: + return result + +if __name__ == '__main__': + from sys import stdin + print get_plaintext_query(stdin.read()) -- cgit v1.2.3-70-g09d2