#!/usr/bin/env python3

from rc.clients import WebSocketClient

MODEL = 'api_requests'
MODEL_ID = None

def callback(apiRequest):
  print("APIRequest: {} {} {} {} {} {} {} {} {} {}".format(
    apiRequest['id'],
    apiRequest['endpoint'],
    apiRequest['extra'],
    apiRequest['user'],
    apiRequest['updater_is_project'],
    apiRequest['updater_id'],
    apiRequest['updated_datetime'],
    apiRequest['created_datetime'],
    apiRequest['success'],
    apiRequest['meta']
  ))


if __name__ == '__main__':
  client = WebSocketClient(MODEL, MODEL_ID, callback)
  client.connect()
  client.run_forever()
#!/usr/bin/env python3

from rc.clients import WebSocketClient
import time

MODEL = 'channels'
# Can be None to listen to changes on all Channels
MODEL_ID = 1

def callback(instance):
  print("New Channel Value: {}".format(instance['value']))

if __name__ == '__main__':
  client = WebSocketClient(MODEL, MODEL_ID, callback, base_url="ws://127.0.0.1:1984")
  client.connect()
  
  while True:
    if client.terminated:
      print("Disconnected")

      client._th.join()
      break

    print("Still connected")
    time.sleep(5)