Allows you to create bots for turntable.fm.
Project description
## Installation
### Using pip
pip install ttapi
### Via source
Obtain the source by downloading from the web or cloning with git. In the
directory containing setup.py run:
python setup.py install
## Examples
### Chat bot
This bot respond to anybody who write "/hello" on the chat.
```py
from ttapi import Bot
bot = Bot(AUTH, USERID, ROOMID)
def speak(data):
name = data['name']
text = data['text']
if text == '/hello':
bot.speak('Hey! How are you %s ?' % name)
bot.on('speak', speak)
bot.start()
```
### Simple
```py
from ttapi import Bot
bot = Bot(AUTH, USERID, ROOMID)
# Define callbacks
def roomChanged(data): print 'The bot has changed room.', data
def speak(data): print 'Someone has spoken.', data
def updateVotes(data): print 'Someone has voted.', data
def registered(data): print 'Someone registered.', data
# Bind listeners
bot.on('roomChanged', roomChanged)
bot.on('speak', speak )
bot.on('update_votes', updateVotes)
bot.on('registered', registered )
# Start the bot
bot.start()
```
### Using pip
pip install ttapi
### Via source
Obtain the source by downloading from the web or cloning with git. In the
directory containing setup.py run:
python setup.py install
## Examples
### Chat bot
This bot respond to anybody who write "/hello" on the chat.
```py
from ttapi import Bot
bot = Bot(AUTH, USERID, ROOMID)
def speak(data):
name = data['name']
text = data['text']
if text == '/hello':
bot.speak('Hey! How are you %s ?' % name)
bot.on('speak', speak)
bot.start()
```
### Simple
```py
from ttapi import Bot
bot = Bot(AUTH, USERID, ROOMID)
# Define callbacks
def roomChanged(data): print 'The bot has changed room.', data
def speak(data): print 'Someone has spoken.', data
def updateVotes(data): print 'Someone has voted.', data
def registered(data): print 'Someone registered.', data
# Bind listeners
bot.on('roomChanged', roomChanged)
bot.on('speak', speak )
bot.on('update_votes', updateVotes)
bot.on('registered', registered )
# Start the bot
bot.start()
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ttapi-1.2.0.tar.gz
(6.9 kB
view details)
File details
Details for the file ttapi-1.2.0.tar.gz
.
File metadata
- Download URL: ttapi-1.2.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7711b19d89815bd011108d7c3ec6c4c0ffd7bcc4f76867dc99cb74dcb734be2 |
|
MD5 | 4e24f6e2d8541a3ec76e24c369db1c40 |
|
BLAKE2b-256 | d114a95a0822ab266b84ba2e7364ac3470403724a5cddb4f07c1fa9981d2e80e |