<s> import datetime <EOL> from activitystreams import settings <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from wellrested import JsonRestClient <EOL> class ActivityStream ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _client = JsonRestClient ( settings . ACTIVITYSTREAMS_BASE_URL , settings . ACTIVITYSTREAMS_USERNAME , settings . ACTIVITYSTREAMS_PASSWORD ) <EOL> def record_activity ( self , action_slug = None , user_id = None , direct_object = None , indirect_object = None , timestamp = None , context = None ) : <EOL> try : <EOL> if timestamp is None : <EOL> timestamp = datetime . datetime . now ( ) <EOL> response = self . _client . post ( <EOL> '<STR_LIT>' % settings . ACTIVITYSTREAMS_SOURCE , <EOL> data = { <EOL> '<STR_LIT:action>' : action_slug , <EOL> '<STR_LIT>' : user_id , <EOL> '<STR_LIT>' : direct_object and ContentType . objects . get_for_model ( direct_object ) . id or None , <EOL> '<STR_LIT>' : direct_object and direct_object . pk or None , <EOL> '<STR_LIT>' : indirect_object and ContentType . objects . get_for_model ( indirect_object ) . id or None , <EOL> '<STR_LIT>' : indirect_object and indirect_object . pk or None , <EOL> '<STR_LIT>' : context , <EOL> } <EOL> ) <EOL> except : <EOL> pass </s>
