Exemple #1
0
 def tpsvrinit(self, args):
     self._rates = None
     t.userlog('Server startup')
     t.tpadvertise('GETRATE')
     t.tpadvertisex('RELOAD_' + str(os.getpid()), 'RELOAD',
                    t.TPSINGLETON + t.TPSECONDARYRQ)
     return 0
Exemple #2
0
 def GETRATE(self, args):
     if self._rates is None:
         t.userlog('Loading rates')
         f = urllib.request.urlopen(
             'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
         )
         x = et.fromstring(f.read().decode('utf8'))
         self._rates = {}
         for r in x.findall('.//*[@currency]'):
             self._rates[r.attrib['currency']] = float(r.attrib['rate'])
     return t.tpreturn(t.TPSUCCESS, 0,
                       {'RATE': self._rates[args['CURRENCY'][0]]})
Exemple #3
0
    def do_POST(self):
        content = self.rfile.read(int(self.headers.get('Content-Length', '0')))
        if content:
            t.userlog('Received ' + str(content))
            data = json.loads(content)

            for k, v in data.items():
                _, _, buf = t.tpcall('GETRATE', {'CURRENCY': k}, t.TPNOTRAN)
                data = {'EUR': str(float(v) / buf['RATE'][0])}

            content = json.dumps(data).encode('utf-8')
            t.userlog('Returning ' + str(content))

            self.send_response(200)
            self.send_header("Content-type", "application/json")
            self.end_headers()
            self.wfile.write(content)
            return
        else:
            self.send_response(500)
            self.end_headers()
            return 'no request'
Exemple #4
0
 def RELOAD(self, args):
     t.userlog('Singleton called with' + str(args))
     self._rates = None
     return t.tpreturn(t.TPSUCCESS, 0, {})
Exemple #5
0
 def tpsvrdone(self):
     t.userlog('Server shutdown')
Exemple #6
0
 def tpsvrinit(self, args):
     t.userlog('Server startup')
     self.db = cx_Oracle.connect(handle=t.xaoSvcCtx())
     t.tpadvertise('DB')
     return 0
Exemple #7
0
 def tpsvrinit(self, args):
     self.db = {}
     t.userlog('Server startup')
     t.tpadvertise('MEMPUT')
     t.tpadvertise('MEMGET')
     return 0
Exemple #8
0
 def tpsvrthrdone(self):
     t.userlog('Server thread shutdown')
Exemple #9
0
 def tpsvrthrinit(self, args):
     t.userlog('Server thread startup')
     return 0
Exemple #10
0
 def tpsvrinit(self, args):
     t.userlog('Server startup')
     threading.Thread(target=serve, daemon=True).start()
     return 0
Exemple #11
0
def serve():
    socketserver.ThreadingTCPServer.allow_reuse_address = True
    with socketserver.ThreadingTCPServer(("", PORT), Handler) as httpd:
        t.userlog('serving at port ' + str(PORT))
        httpd.serve_forever()