Last active
September 16, 2015 18:12
-
-
Save richcaudle/cad8cc77473811f49a5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would I grab individual records to e.g. filter/process/enhance and then move them per HTTP to somewhere else ? (Sorry, Python beginner)