-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverend.py
75 lines (63 loc) · 1.74 KB
/
serverend.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
68
69
70
71
72
73
74
75
import tornado.ioloop
from tornado.web import *
import win32api
import ImageGrab
#########################
# Configuration options #
#########################
tornado_options = {
"port": 8888
}
#########################
# Handlers go here #
#########################
class MainHandler(RequestHandler):
def get(self):
self.render("index.html")
class DoublerHandler(RequestHandler):
def get(self):
x = self.get_argument("x")
y = self.get_argument("y")
c = self.get_argument("c")
print(x + ", " + y + ", " + c)
tempx = open("tempx", "w")
tempy = open("tempy", "w")
if (c=='true'):
print("inside")
click = open("click", "w")
click.write(c)
click.close()
tempx.write(x)
tempy.write(y)
tempx.close()
tempy.close()
class ImageHandler(RequestHandler):
def get(self):
#first, update the screenshot
img = ImageGrab.grab()
img.save('test.jpg','JPEG')
#now, encode it and send it over
k = None
with open("test.jpg", "rb") as f:
data = f.read()
k=data.encode("base64")
self.write(k)
###### get ends here ######
############################
# Routes go here #
############################
application = tornado.web.Application([
(r"/", MainHandler),
(r"/doubler", DoublerHandler),
(r"/getimage", ImageHandler)
###### routes end here ######
#########################
# Don't change this #
#########################
], debug=True,
template_path=os.path.join(os.path.dirname(__file__), ""),
static_path=os.path.join(os.path.dirname(__file__), ""),
)
if __name__ == "__main__":
application.listen(tornado_options["port"])
tornado.ioloop.IOLoop.instance().start()