Created
December 15, 2014 13:02
-
-
Save tschellenbach/b0f1cf65647cb0acd0ef to your computer and use it in GitHub Desktop.
GetStream.io aggregated notification feed example
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
# 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