Exemple #1
0
# receiver.py

from socketio import Client

socketio = Client()
socketio.connect("http://*****:*****@socketio.on("message")
def on_message(message):
    jbt = message.get("message")
    print(jbt)


socketio.wait()
Exemple #2
0
    def on_disconnect(self):
        print('on_disconnect')

    def get_current_price(self):
        tickers = pyupbit.get_tickers(fiat="KRW")

        while True:
            markets = pyupbit.get_current_price(tickers)
            client.emit(
                "send_price",
                dict(tickers=tickers, markets=markets, size=len(markets)))
            time.sleep(1)


client = UpbitClientNamespace('/upbit')

sio = Client()
sio.register_namespace(client)
sio.connect('http://localhost:3000', namespaces=['/upbit'])

sio.start_background_task(client.get_current_price)

print(sio.connected)
print(sio.connection_namespaces)

try:
    sio.wait()
except KeyboardInterrupt as e:
    if sio.connected:
        sio.disconnect()
Exemple #3
0
        send('is-provisioned', ssh=ssh, web=web, web_ro=web_ro)
    elif data['state'] == 'want-deprovision':
        print('Server wants a deprovision')
        if is_provisioned:
            print('Deprovisioning...')
            code = run_external(['deprovision.sh'])
            if code:
                print('ERROR: deprovision.sh failed with exit code %d' % code,
                      file=sys.stderr)
                send('deprovision-failed')
                return
            is_provisioned = False
        else:
            print('Already deprovisioned, nothing to do')
        send('is-deprovisioned')
    elif data['state'] == 'update-expiration':
        print('Updating expiration timestamp')
        with open(os.environ['EXPIRATION_TIMESTAMP'], 'w') as f:
            f.write(str(int(data['expiration'])))


def send(state, **kwargs):
    kwargs['state'] = state
    print('Sending %r to server' % kwargs)
    c.send(kwargs, namespace='/device')


c.connect('https://localhost:5000', headers=auth_hdr)
c.wait()
sys.exit(error)