Skip to content

Instantly share code, notes, and snippets.

@richcaudle
Last active September 16, 2015 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richcaudle/cad8cc77473811f49a5f to your computer and use it in GitHub Desktop.
Save richcaudle/cad8cc77473811f49a5f to your computer and use it in GitHub Desktop.
# 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
Copy link

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