Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Include the DataSift library
import datasift
# Create a client
client = datasift.Client('DATASIFT_USERNAME', 'DATASIFT_API_KEY')
# Declare a filter in CSDL, looking for content mentioning music
csdl = 'interaction.content contains "music"'
# Compile the filter
fltr = client.compile(csdl)
# Handler: Message deleted by user
@client.on_delete
def on_delete(interaction):
print "You must delete this to be compliant with T&Cs: ", interaction
# Handler: Connection was closed
@client.on_closed
def on_close(wasClean, code, reason):
print "Stream subscriber shutting down because ", reason
# Handler: Picks up any error, warning, information messages from the platform
@client.on_ds_message
def on_ds_message(msg):
print( 'DS Message %s' % msg)
# Handler: Connected to DataSift
@client.on_open
def on_open():
print "Connected to DataSift"
@client.subscribe(fltr['hash'])
def on_interaction(interaction):
print "Recieved interaction: ", interaction
# Start streaming
client.start_stream_subscriber()
@aosterloh

This comment has been minimized.

Copy link

aosterloh commented Sep 16, 2015

How would I grab individual records to e.g. filter/process/enhance and then move them per HTTP to somewhere else ? (Sorry, Python beginner)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.