-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
39 lines (30 loc) · 901 Bytes
/
test.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
# -*- coding:utf-8
import os
import subprocess
import web
import time
import requests
from web.wsgiserver import CherryPyWSGIServer
def img_to_string(img,clear=True,plus=""):
subprocess.check_output('tesseract '+img+''+img,shell=True)
with open(path+'.txt') as f:
txt = f.read().strip()
if clear:
os.remove(img+'.txt')
return txt
urls = ('/api','Ajax')
class Ajax(object):
def POST(self):
web.header('Content-Security-Policy','upgrade-insecure-requests',unique=True)
data = web.input()
print data
req = requests.get(data)
with open('st.img','wb') as f:
f.write(req.content)
value = img_to_string('st.img')
return value
if __name__ == '__main__':
#CherryPyWSGIServer.ssl_certificate = 'server.crt'
#CherryPyWSGIServer.ssl_private_key = 'server.key'
app = web.application(urls,globals())
app.run()