-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWolframalphahelper.py
61 lines (46 loc) · 1.61 KB
/
Wolframalphahelper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy
import wolframalpha
import xml.etree.cElementTree as ET
import urllib2
import time
from random import randrange
# Written by Junlin Wang
def construct(levelmin = 1, levelmax = 7, anglemin = 20, anglemax = 90):
root = ET.Element("root")
collect = {}
a = open('lengthdata.txt','w')
for level in range(levelmin, levelmax + 1):
for angle in range(anglemin, anglemax + 1):
print angle
segmentLength = 2.0 * numpy.cos(angle/180.0 * numpy.pi) + 2
base = 4.0/segmentLength
length = base**level
ininch = length * 6
appid = 'E929YY-HRP2LA22AV'
client = wolframalpha.Client(appid)
try:
res = client.query('how long is %0.2f' % (ininch) + ' inches')
except urllib2.HTTPError:
tree = ET.ElementTree(root)
tree.write("learninglength.xml")
a.write('stop at level: %d, angle: %d' %(level, angle))
text = ''
for pod in res.pods:
if pod.text[1] == "~":
new = pod.text.encode('ascii', 'replace')
new = new.replace('?', '*')
text = text + new + ' '
key = ET.SubElement(root, "finches%0.2f" % (ininch))
key.text = text
collect['%0.2finches'%(ininch)] = text
'''
a.write('')
a.write(text)
a.write('\n')
'''
tree = ET.ElementTree(root)
tree.write("learninglength.xml")
return collect
construct(1, 7, 10, 90)
def find(level, angle):
pass