nodes: 0, module; 1, function_definition; 2, function_name:setActivities; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, dictionary_splat_pattern; 8, expression_statement; 9, function_definition; 10, try_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, identifier:args; 15, identifier:kwargs; 16, comment:"""Adds the activities for this group to a 'activities' field.
  
          Activities are MambuActivity objects.
  
          Activities get sorted by activity timestamp.
  
          Returns the number of requests done to Mambu.
          """; 17, function_name:activityDate; 18, parameters; 19, block; 20, block; 21, except_clause; 22, assignment; 23, assignment; 24, integer:1; 25, identifier:activity; 26, expression_statement; 27, try_statement; 28, expression_statement; 29, as_pattern; 30, block; 31, attribute; 32, call; 33, subscript; 34, identifier:activities; 35, comment:"""Util function used for sorting activities according to timestamp"""; 36, block; 37, except_clause; 38, assignment; 39, identifier:AttributeError; 40, as_pattern_target; 41, import_from_statement; 42, expression_statement; 43, expression_statement; 44, identifier:activities; 45, identifier:attrs; 46, identifier:sorted; 47, argument_list; 48, identifier:self; 49, string; 50, return_statement; 51, as_pattern; 52, block; 53, identifier:activities; 54, call; 55, identifier:ae; 56, relative_import; 57, dotted_name; 58, assignment; 59, assignment; 60, attribute; 61, keyword_argument; 62, string_content:activities; 63, subscript; 64, identifier:KeyError; 65, as_pattern_target; 66, return_statement; 67, attribute; 68, argument_list; 69, import_prefix; 70, dotted_name; 71, identifier:MambuActivities; 72, attribute; 73, identifier:MambuActivities; 74, identifier:activities; 75, call; 76, identifier:activities; 77, identifier:attrs; 78, identifier:key; 79, identifier:activityDate; 80, subscript; 81, string; 82, identifier:kerr; 83, None; 84, identifier:self; 85, identifier:mambuactivitiesclass; 86, keyword_argument; 87, list_splat; 88, dictionary_splat; 89, identifier:mambuactivity; 90, identifier:self; 91, identifier:mambuactivitiesclass; 92, attribute; 93, argument_list; 94, identifier:activity; 95, string; 96, string_content:timestamp; 97, identifier:groupId; 98, subscript; 99, identifier:args; 100, identifier:kwargs; 101, identifier:self; 102, identifier:mambuactivitiesclass; 103, keyword_argument; 104, list_splat; 105, dictionary_splat; 106, string_content:activity; 107, identifier:self; 108, string; 109, identifier:groupId; 110, subscript; 111, identifier:args; 112, identifier:kwargs; 113, string_content:encodedKey; 114, identifier:self; 115, string; 116, string_content:encodedKey
code: def setActivities(self, *args, **kwargs):
          """Adds the activities for this group to a 'activities' field.
  
          Activities are MambuActivity objects.
  
          Activities get sorted by activity timestamp.
  
          Returns the number of requests done to Mambu.
          """
          def activityDate(activity):
              """Util function used for sorting activities according to timestamp"""
              try:
                  return activity['activity']['timestamp']
              except KeyError as kerr:
                  return None
          try:
              activities = self.mambuactivitiesclass(groupId=self['encodedKey'], *args, **kwargs)
          except AttributeError as ae:
              from .mambuactivity import MambuActivities
              self.mambuactivitiesclass = MambuActivities
              activities = self.mambuactivitiesclass(groupId=self['encodedKey'], *args, **kwargs)
  
          activities.attrs = sorted(activities.attrs, key=activityDate)
          self['activities'] = activities
  
          return 1