-
Notifications
You must be signed in to change notification settings - Fork 9
/
oldMain.py
67 lines (55 loc) · 1.68 KB
/
oldMain.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
58
59
60
61
62
63
64
65
66
67
import falcon
import json
import sys
import codecs
import urllib
import html
import time
import requests
#from BeautifulSoup import BeautifulSoup
sys.path.insert(0, 'solver')
import SI
TOKEN = "441560082:AAEIdBz5_y0gfY-DgAbJ2TuJbWy3EVZeN9c"
URL = "https://api.telegram.org/bot{}/".format(TOKEN)
class ThingsResource(object):
def on_get(self, req, resp,filename):
"""Handles GET requests"""
resp.status = falcon.HTTP_200
resp.content_type = 'text/html'
with open(filename, 'r') as f:
resp.body = f.read()
class Starting(object):
#def on_get(self, req, resp):
# p = ('\nTwo things awe me most, the starry sky '
# 'above me and the moral law within me.\n'
# '\n'
# ' ~ Immanuel Kant\n\n')
# print("p")
def on_post(self,req,resp):
t0 = time.time()
print("called\n\n")
data=req.stream.read()
print(data)
print("\n\n\nnow printing resolved \n\n")
data=data.decode()
data=json.loads(data)
print(data["result"]["resolvedQuery"])
answer=SI.mainp(data["result"]["resolvedQuery"])
answer=str(answer)
print(answer)
d={}
d["type"]=0
d["siaplayText"]="The answer is "+str(answer)
d["speech"]="The answer is "+str(answer)
d["answer"]=answer
resp.body = json.dumps(d, ensure_ascii=False)
resp.status = falcon.HTTP_200
t1 = time.time()
total = t1-t0
print("\n\n\n\n time taken")
print(total)
app = falcon.API()
things = ThingsResource()
thi = Starting()
app.add_route('/things/{filename}', things)
app.add_route('/things',thi)