Skip to content

Instantly share code, notes, and snippets.

@justinplatz
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save justinplatz/f9b5d72b00ae2b9518fe to your computer and use it in GitHub Desktop.

Select an option

Save justinplatz/f9b5d72b00ae2b9518fe to your computer and use it in GitHub Desktop.
#Kill PubNub subscription thread
def _kill(m, n):
pubnub.unsubscribe(subchannel)
# ==============================Define Main==================================
def main():
print("Starting Main")
pubnub = Pubnub(publish_key = 'demo',
subscribe_key = 'demo',
uuid = "pi")
channel = 'my_channel'
def _callback(m,n):
# ==============================Left Hand==============================
left_hand = m.get("left_hand",{})
if left_hand != {}:
handleLeft(left_hand)
# ==============================Right Hand=============================
right_hand = m.get("right_hand",{})
if right_hand != {}:
handleRight(right_hand)
#Catch and Print Error
def _error(m):
print(m)
#Subscribe to subchannel, set callback function to _callback and set error fucntion to _error
pubnub.subscribe(channels=channel, callback=_callback, error=_error, connect=_error)
# ==============================Call Main====================================
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment