alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
317 stars 97 forks source link

bot.roomInfo() in Python #190

Closed kgleason closed 11 years ago

kgleason commented 11 years ago

I apologize for this if is not the right place for this question. I've managed to get quite a bit done already with the Python version of the ttapi, but I'm stuck on the bot.roomInfo().

Here is a sample of what I'm trying to do:

from ttapi import Bot
myAuthID = 'XXX'
myUserID = 'XXX'
defaultRoomID = 'XXX'
bot = Bot(myAuthID, myUserID, defaultRoomID)

def roomChanged(data):
    print 'data:', data
    data2 = bot.roomInfo()
    print 'data2:', data2
bot.on('roomChanged',   roomChanged)
bot.start()

so when I fire this off, my bot connects, and get output that looks like this:

data: {    ...    all kinds of room info   ...   }
data2: None

If I'm reading the docs properly, I was expecting to see data2 to look similar to data.

According to the docs, it looks as if the callback function isn't required; but the only way I ever get results from bot.roomInfo is if I actually use a callback function.

If I'm reading it all wrong, then I sincerely apologize.

alaingilbert commented 11 years ago

Hi ! This question is at the very right place :) Basically, every call made to turntable.fm are async and need a callback if you want to do something with the result. So you are right, the documentation says that the callback is optional, but, if you don't have a callback, the "roomInfo" call become kinda useless. (Which mean, I should probably fix the documentation !)

from ttapi import Bot
bot = Bot(AUTH, USERID, ROOMID)

def roomInfo(data):
    print data

def roomChanged(data):
    print 'data:', data
    bot.roomInfo(roomInfo)

bot.on('roomChanged',   roomChanged)
bot.start()
from ttapi import Bot
bot = Bot(AUTH, USERID, ROOMID)

def roomChanged(data):
    def roomInfo(data2):
        print data2
    print 'data:', data
    bot.roomInfo(roomInfo)

bot.on('roomChanged',   roomChanged)
bot.start()

I think that both example should work properly.

kgleason commented 11 years ago

Thanks. There are a couple of these that I've noticed, so I might just submit a pull request for the documentation, but it probably won't be until later in the week. Thanks for the speedy response.

ghost commented 11 years ago

^make sure you close the issue once it solves your question, kgleason

alaingilbert commented 11 years ago

@kgleason Don't be shy to open a pull request :D