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]]})
def PROXY(self, data, name, flags): future = asyncio.run_coroutine_threadsafe( on_service(name, data, flags), loop) rval, rcode, data = future.result(timeout=5) return t.tpreturn(rval, rcode, data)
def RELOAD(self, args): t.userlog('Singleton called with' + str(args)) self._rates = None return t.tpreturn(t.TPSUCCESS, 0, {})
def DB(self, args): dbc = self.db.cursor() dbc.execute('insert into pymsg(msg) values (:1)', ['Hello from python']) return t.tpreturn(t.TPSUCCESS, 0, args)
def MEMGET(self, args): args['VALUE'] = [] for key in args['KEY']: args['VALUE'].append(self.db.get(key, '')) return t.tpreturn(t.TPSUCCESS, 0, args)
def MEMPUT(self, args): for key, value in zip(args['KEY'], args['VALUE']): self.db[key] = value return t.tpreturn(t.TPSUCCESS, 0, {})
def TUX2(self, data): if "TA_STATUS" not in data: data["TA_STATUS"] = [] data["TA_STATUS"].append("Hello from TUX2") _, _, data = t.tpcall("NATS1", data, t.TPNOTRAN) return t.tpreturn(t.TPSUCCESS, 0, data)
def TUX1(self, data): if "TA_STATUS" not in data: data["TA_STATUS"] = [] data["TA_STATUS"].append("Hello from TUX1") return t.tpreturn(t.TPSUCCESS, 0, data)