Giter Site home page Giter Site logo

Process the received data about pysher HOT 4 CLOSED

deepbrook avatar deepbrook commented on August 11, 2024
Process the received data

from pysher.

Comments (4)

deepbrook avatar deepbrook commented on August 11, 2024 2

To process the data, you simply need to define a function to run as a callback:

import pysher

# Add a logging handler so we can see the raw communication data
import logging
root = logging.getLogger()
root.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
root.addHandler(ch)

pusher = pysher.Pusher(appkey)

def  callback(*args, **kwargs):
    print("processing Args:", args)
    print("processing Kwargs:", kwargs)

# We can't subscribe until we've connected, so we use a callback handler
# to subscribe when able
def connect_handler(data):
    channel = pusher.subscribe('mychannel')
    channel.bind('myevent', callback)

pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()

while True:
    # Do other things in the meantime here...
    time.sleep(1)

from pysher.

pedrorojasg avatar pedrorojasg commented on August 11, 2024

Thank you for answer so fast! How should I get the message that is printed in every iteration in the log?

My code:

    root = logging.getLogger()
    root.setLevel(logging.INFO)
    ch = logging.StreamHandler(sys.stdout)
    root.addHandler(ch)

    pusher = pysher.Pusher('de504dc5763aeef9ff52')
    def  callback(*args, **kwargs):
        print("processing Args:", args)
        # some code to send the data to a client whit Django Channels

    # We can't subscribe until we've connected, so we use a callback handler
    # to subscribe when able
    def connect_handler(data):
        channel = pusher.subscribe('live_trades')
        channel.bind('trade', callback({'data': data}))

    pusher.connection.bind('pusher:connection_established', connect_handler)
    pusher.connect()

    while True:
        # Do other things in the meantime here...
        time.sleep(1)

I'm getting this error:
error from callback <bound method Connection._on_message of <Connection(Thread-2, started daemon 139676136490752)>>: 'NoneType' object is not callable

from pysher.

pedrorojasg avatar pedrorojasg commented on August 11, 2024

Thank you bro!!! I did it with your help and in the way I learn how to use args.

You could close this Issue.

My final code:

    root = logging.getLogger()
    root.setLevel(logging.INFO)
    ch = logging.StreamHandler(sys.stdout)
    root.addHandler(ch)

    pusher = pysher.Pusher('de504dc5763aeef9ff52')
    def  callback(*args, **kwargs):
        self.send_json(json.loads(args[0]))

    # We can't subscribe until we've connected, so we use a callback handler
    # to subscribe when able
    def connect_handler(data):
        channel = pusher.subscribe('live_trades')
        channel.bind('trade', callback)

    pusher.connection.bind('pusher:connection_established', connect_handler)
    pusher.connect()

from pysher.

robinCantelli avatar robinCantelli commented on August 11, 2024

Hey,
I struggled the last few days with getting pusher data from bitsamp via python. Today I found this here and got it runnig with the example code on this channel. My problem is similar to yours. I want to get the data that is printed on my console as a dict so that I can do some calculations with it. My problem is that this whole code and every finction and method is somehow a blackbox for me. Can you help me with that please?

What I usually did was getting the data and then process it like:

def btstamp_XRP(Coin_B):
bitStampTick = requests.get('https://www.bitstamp.net/api/v2/order_book/xrpeur')
a = []
a = bitStampTick.json()['bids'][0] + bitStampTick.json()['asks'][0]

and than having my main program doing that calcs.

what i would like to is actually the same

def pusher:
geting that real time data

then on a certain point id like to take the realtime data which is fix in my varialble when I call it and then work with it.

But how do I get a dict?

Thanks!

PS: I also want the program to stop printing those big dicts all the time;)

from pysher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.