from wsgiref.simple_server import make_server from pyramid.config import Configurator from pyramid_rpc.jsonrpc import jsonrpc_method from b64_image import to_img from ocr_ktp.ktp import ocr @jsonrpc_method(endpoint='rpc') def ocr_ktp(request, p): img = to_img(p['foto']) r = ocr(img) if 'Tgl_Lahir' in r: r['Tgl_Lahir'] = r['Tgl_Lahir'].strftime('%d-%m-%Y') return r with Configurator() as config: config.include('pyramid_rpc.jsonrpc') config.add_jsonrpc_endpoint('rpc', '/rpc') config.scan(__name__) app = config.make_wsgi_app() port = 8000 server = make_server('0.0.0.0', port, app) print('Listen web on port {}'.format(port)) server.serve_forever()