Skip to content

Instantly share code, notes, and snippets.

@tschellenbach
Created December 15, 2014 13:02
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 tschellenbach/c82e3fb4c5ec06358a8e to your computer and use it in GitHub Desktop.
Save tschellenbach/c82e3fb4c5ec06358a8e to your computer and use it in GitHub Desktop.
GetStream.io aggregated notification feed example with if statement
# Instantiate a new client
import stream
client = stream.connect('key', 'secret')
# Assume the notification is aggregated on
# {% if verb.infinitive == 'like' %}{{ object }}{% else %}{{ id }}{% endif %}
notification_feed = client.feed('notification', '1')
# Add two likes, one comment and two follows
activities = [
{"actor": "User:Thierry", "verb": "like", "object": "Place:Fuerteventura"},
{"actor": "User:Austin", "verb": "like", "object": "Place:Fuerteventura"},
{"actor": "User:Tommaso", "verb": "comment", "object": "Comment:1", "message": "Awesome trip"},
{"actor": "User:Tommaso", "verb": "follow", "object": "User:Justin"},
{"actor": "User:Thierry", "verb": "follow", "object": "User:Justin"},
]
activity_response = notification_feed.add_activities(activities)
# Read the feed and check how data is aggregated
aggregated_activities = notification_feed.get()
for aggregated in aggregated_activities['results']:
actors = [a['actor'] for a in aggregated['activities']]
print aggregated['group'], actors
'''
Output should look something like this:
39a16456-845a-11e4-8080-8001454ee5b4 [u'User:Thierry']
39a15cfe-845a-11e4-8080-800163eedaf8 [u'User:Tommaso']
39a1160e-845a-11e4-8080-80001462b03e [u'User:Tommaso']
Place:Fuerteventura [u'User:Austin', u'User:Thierry']
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment