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

Python: Changing isinstance str to basestring #80

Closed BenTheHokie closed 12 years ago

BenTheHokie commented 12 years ago

basestring checks if the value is a str or unicode type so that either can be used because unicode data is sent to the bot. Unicodes don't register in Python as strings but unicodes register as basestring types. Since unicodes are sent, unicode data cannot be shipped back because unicodes won't register as strings in the API. Eg:

def newSong(data):
    global genre,artist,lameGenres,lameArtists
    songData = data['room']['metadata']['current_song']
    DJid = songData['djid']  # THIS DATA IS A UNICODE TYPE!
    artist = songData['metadata']['artist']
    genre = songData['metadata']['genre']
    for i in range(len(lameGenres)): # Note: for loop is used because lameGenres contains substrings of disallowed genres in case there are 2 different genres such as "Rap" and "Rap/Hip Hop"
        if lameGenres[i].lower() in genre.lower():
            eebot.remDj(DJid) # REMDJ WILL NOT WORK WITH UNICODE TYPES!
            eebot.speak('%s is not allowed!' % genre)
            break
    for i in range(len(lameArtists)):
        if lameArtists[i].lower() in artist.lower():
            eebot.remDj(DJid) # SAME AS ABOVE
            eebot.speak('This kind of music is not allowed!')
            break

TLDR: basestring checks for str and unicode types

alaingilbert commented 12 years ago

Thanks for your help ! :)

BenTheHokie commented 12 years ago

Your welcome but something tells me there are 0 people besides me who use the Python version.