Commits

caedes committed f4c2eca

remove elggconnect from cryptobot, moved to: http://bitbucket.org/rhizomatik/python-elggconnect

  • Participants
  • Parent commits 18be75a

Comments (0)

Files changed (1)

File elggconnect.py

-import time
-import MySQLdb
-
-ACCESS_DEFAULT = -1
-ACCESS_PRIVATE = 0
-ACCESS_LOGGED_IN = 1
-ACCESS_PUBLIC = 2
-ACCESS_FRIENDS = -2
-
-def format_sql(val):
-    if isinstance(val, str):
-        return MySQLdb.string_literal(val)
-    else:
-        return str(val)
-
-class ElggEntity(object):
-    def __init__(self, guid, db, type=None):
-        self.guid = guid
-        self._db = db
-        if type:
-            self._type = type
-        else:
-            self._type = self._db.get_entity_property(self.guid, 'type')
-    def __repr__(self):
-        return self.__str__()
-    def __str__(self):
-        try:
-            name = self.name
-        except:
-            name = self.title
-        if not name:
-            print self.type,self.keys()
-        return "ElggEntity(%s, '%s:%s', '%s')" % (self.guid, self.type, self.getSubtype(), name)
-    def __setattr__(self, name, value):
-        if name in ['guid','_db','_type']:
-            object.__setattr__(self, name, value)
-        else:
-            self.setProperty(name, value)
-    def __eq__(self, other):
-        return other.__class__ == self.__class__ and self.guid == other.guid
-    def __ne__(self, other):
-        return not self.__eq__(other)
-    def __getattr__(self, name):
-        return self.getProperty(name)
-    def getRelationships(self):
-        return self._db.get_entity_relationships(self.guid)
-    def getContainer(self):
-        guid = self.getProperty('container_guid')
-        if guid:
-            return ElggEntity(guid, self._db)
-    def getOwner(self):
-        guid = self.getProperty('owner_guid')
-        if guid:
-            return ElggEntity(guid, self._db)
-    def getSite(self):
-        guid = self.getProperty('site_guid')
-        if guid:
-            return ElggEntity(guid, self._db)
-    def getSubtype(self):
-        subtype = self.getProperty('subtype')
-        return self._db.get_entity_subtype_name(subtype)
-    def delProperty(self, name):
-        return self._db.delete_metadata(self.guid, name)
-    def getProperty(self, name):
-        return self._db.get_entity_property(self.guid, name, self._type)
-    def setProperty(self, name, value):
-        return self._db.set_entity_property(self.guid, name, value, self._type)
-    def keys(self):
-        return self._db._entity_props + self._db.get_pertype_props(self._type) + self._db.get_metadata_keys(self.guid)
-    def printAll(self):
-        print self
-        for key in self.keys():
-            print " *",key,self.getProperty(key)
-
-        for relationship in self.getRelationships():
-            print " -", relationship
-            for a in set(self._db.get_relationship(self.guid, relationship)).union(self._db.get_relationship_inverse(self.guid, relationship)):
-                print "  -",self._db.getEntity(a)
-
-
-class ElggConnect(object):
-    def __init__(self, host, user, passwd, db, prefix='elgg', connect=True):
-        self._prefix = prefix
-        self.connect(host, user, passwd, db)
-        self._entity_props = self.select_multi("describe "+self._prefix+"entities;")
-        self._pertype_props = {}
-        self._topicid = self.get_entity_subtype('groupforumtopic')
-        self._metastring_cache = {}
-        self._metastringid_cache = {}
-        self.threaded_forums = True
-    def connect(self, host, user, passwd, db):
-        self._sql = MySQLdb.connect(host, user, passwd, db)
-        self._sql.set_character_set("utf8")
-    def close(self):
-        self._sql.close()
-    def get_pertype_props(self, type):
-        if not type in self._pertype_props:
-            self._pertype_props[type] = self.select_multi("describe "+self._prefix+type+"s_entity;")
-        return self._pertype_props[type]
-    def query(self, query_string):
-        return self._sql.query(query_string)
-    def insert(self, query_string):
-        self._sql.query(query_string)
-        return self._sql.insert_id()
-    def select_single(self, query_string):
-        #print "insert",query_string
-        self._sql.query(query_string)
-        res = self._sql.store_result()
-        row = res.fetch_row()
-        try:
-            return row[0][0]
-        except:
-            return None
-    def select_data(self, query_string):
-        #print "select_single: ", query_string
-        self._sql.query(query_string)
-        res = self._sql.store_result()
-        row = res.fetch_row()
-        try:
-            return row[0]
-        except:
-            return None
-
-    def select_multi(self, query_string):
-        #print "select_multi: ", query_string
-        objs = []
-        self._sql.query(query_string)
-        res = self._sql.store_result()
-        for i in xrange(res.num_rows()):
-            row = res.fetch_row()
-            objs.append(row[0][0])
-        return objs
-    def add_to_river(self, type, subtype, action_type, view, subject, object, comment_id=0):
-        now = int(time.time())
-        accessid = self.get_accessid(object)
-        return self.insert("insert into "+self._prefix+"river \
-                         (type,subtype,action_type,access_id,view,subject_guid,object_guid,posted, annotation_id)\
-                             values ('%s','%s','%s',%s,'%s',%s,%s,%s,%s);"%(type,
-                                                                      subtype,
-                                                                      action_type,
-                                                                     accessid, view,
-                                                                      subject,
-                                                                      object,
-                                                                         now,
-                                                                         comment_id))
-    # good
-    def getEntity(self, *args):
-        if len(args) == 1:
-            if isinstance(args[0],(int,long)):
-		    guid = args[0]
-		    if guid:
-			return ElggEntity(guid, self)
-        elif len(args) == 2:
-            guid = self.get_entity_frommeta(*args)
-            if guid:
-                return ElggEntity(guid, self)
-        elif len(args) == 3:
-            guid = self.get_entity_fromproperty(*args)
-            if guid:
-                return ElggEntity(guid, self, args[2])
-    def getEntities(self, *args):
-        if len(args) == 1:
-            type = str(args[0])
-            if type in ['user','site','object','group']:
-                guids = self.select_multi("select guid from "+self._prefix+"entities where type='"+type+"'")
-                return map(lambda guid: ElggEntity(guid, self),guids)
-            else:
-                guids = self.get_entities_withmeta(type)
-                return map(lambda guid: ElggEntity(guid, self),guids)
-        elif len(args) == 2:
-            guids = self.get_entities_frommeta(*args)
-            return map(lambda guid: ElggEntity(guid, self),guids)
-        elif len(args) == 3:
-            guids = self.get_entities_fromproperty(*args)
-            return map(lambda guid: ElggEntity(guid, self, args[2]),guids)
-
-    def createEntity(self, type, subtype=0, owner_guid=0, group_guid=0, now=False, access=False, args={}):
-        if type=='user' and not access:
-            access = ACCESS_PUBLIC # public
-        guid = self.create_entity(subtype, owner_guid, group_guid, now, access, type)
-        # per object properties
-        internal_props = self.get_pertype_props(type)
-        internal_props = filter(lambda s: s in args, internal_props)
-        prop_names = ", ".join(internal_props)
-        prop_vals = map(lambda s: format_sql(args[s]), internal_props)
-        prop_vals = ", ".join(prop_vals)
-        if prop_names:
-            self.insert("insert into "+self._prefix+type+"s_entity (guid, %s) values (%s, %s);" %(prop_names, guid, prop_vals))
-        else:
-            self.insert("insert into "+self._prefix+type+"s_entity (guid) values (%s);" %(guid,))
-        # extra props
-        extra_props = filter(lambda s: s not in internal_props, args.keys())
-        e = ElggEntity(guid, self, type)
-        for a in extra_props:
-            e.setProperty(a, args[a])
-        return e
-
-    def get_metastring_id(self, astring, autocreate=False):
-        if astring in self._metastringid_cache:
-            return self._metastringid_cache[astring]
-        id = self.select_single("select id from "+self._prefix+"metastrings where \
-                                string=%s;"%(format_sql(astring),))
-        if autocreate and id == None:
-            id = self.insert("insert into "+self._prefix+"metastrings (string)\
-                             values (%s)"%(format_sql(astring),))
-        if id:
-            self._metastringid_cache[astring] = id
-            self._metastring_cache[id] = astring
-        return id
-    def get_metastring(self, id):
-        if id in self._metastring_cache:
-            return self._metastring_cache[id]
-        value = self.select_single("select string from "+self._prefix+"metastrings where \
-                                id=%s;"%(id,))
-        if value:
-            self._metastringid_cache[value] = id
-            self._metastring_cache[id] = value
-        return value
-
-    def get_relationship_inverse(self, guid_two, relationship):
-        self._sql.query("select guid_one from "+self._prefix+"entity_relationships where \
-                        relationship='%s' and guid_two=%s;"%(relationship,
-                        guid_two))
-        res = self._sql.store_result()
-        uids = []
-        for idx in xrange(res.num_rows()):
-                uids.append(res.fetch_row()[0][0])
-        return uids
-    def get_relationship(self, guid_two, relationship):
-        self._sql.query("select guid_two from "+self._prefix+"entity_relationships where \
-                        relationship='%s' and guid_one=%s;"%(relationship,
-                        guid_two))
-        res = self._sql.store_result()
-        uids = []
-        for idx in xrange(res.num_rows()):
-                uids.append(res.fetch_row()[0][0])
-        return uids
-    def get_entity_relationships(self, guid):
-        return set(self.select_multi("select relationship from "+self._prefix+"entity_relationships where \
-                        guid_two=%s or guid_one=%s;"%(guid, guid)))
-
-    def remove_relationship(self, guid_one, relationship, guid_two):
-        if self.check_relationship(guid_one, relationship, guid_two):
-                self._sql.query("delete from "+self._prefix+"entity_relationships where guid_one=%s and guid_two=%s and relationship='%s'"%(guid_one, guid_two, relationship))
-        return
-    def check_relationship(self, guid_one, relationship, guid_two):
-        return self.select_single("select guid_two from "+self._prefix+"entity_relationships where \
-                        relationship='%s' and guid_one=%s and guid_two=%s;"%(relationship,
-                        guid_one, guid_two))
-    def add_relationship(self, guid_one, relationship, guid_two):
-        id = self.select_single("select id from "+self._prefix+"entity_relationships where \
-                                guid_one=%s and relationship='%s' and \
-                                guid_two=%s" % (guid_one, relationship, guid_two))
-        if not id:
-            id = self.insert("insert into "+self._prefix+"entity_relationships (guid_one, \
-                    relationship, guid_two)\
-            values(%s, '%s', %s);" % (guid_one, relationship, guid_two))
-        return id
-
-    def get_entities_frommeta(self, name, value):
-        msg_id = None
-        topicid = None
-        name_id = self.get_metastring_id(name)
-        value_id = self.get_metastring_id(value)
-        if name_id and value_id:
-            return self.select_multi("select entity_guid from "+self._prefix+"metadata where value_id='"+str(value_id)+"' and name_id='"+str(name_id)+"'")
-        return []
-    def get_entities_withmeta(self, name):
-        name_id = self.get_metastring_id(name)
-        if name_id:
-            return set(self.select_multi("select entity_guid from "+self._prefix+"metadata where name_id='"+str(name_id)+"'"))
-        return []
-
-    def get_entity_frommeta(self, name, value):
-        ents = self.get_entities_frommeta(name, value)
-        if ents:
-             return ents[0]
-
-    def get_entities_fromproperty(self, name, value, type):
-        if name in self._entity_props:
-            return self.select_multi("select guid from "+self._prefix+"entities where %s=%s"%(name, format_sql(value)))
-        if name in self.get_pertype_props(type):
-            return self.select_multi("select guid from "+self._prefix+type+"s_entity where %s=%s"%(name, format_sql(value)))
-        return self.get_entities_frommeta(name, value)
-
-    def get_entity_fromproperty(self, name, value, type):
-        ents = self.get_entities_fromproperty(name, value, type)
-        if ents:
-            return ents[0]
-
-    def set_entity_property(self, guid, name, value, type=''):
-        if name in self._entity_props:
-            return self.query("update "+self._prefix+"entities SET %s=%s WHERE \
-                          guid=%s;"%(name, format_sql(value), guid))
-        if not type:
-            type = self.get_entity_property(guid, 'type')
-        if name in self.get_pertype_props(type):
-            return self.query("update "+self._prefix+type+"s_entity SET %s=%s WHERE \
-                          guid=%s;"%(name, format_sql(value), guid))
-        e = self.getEntity(guid)
-        return self.add_metadata(e.owner_guid, 0, guid, name, value)
-
-    def get_entity_property(self, guid, name, type=''):
-        if name in self._entity_props:
-            return self.select_single("select "+name+" from "+self._prefix+"entities where guid="+str(guid))
-        if not type:
-            type = self.get_entity_property(guid, 'type')
-        if name in self.get_pertype_props(type):
-            return self.select_single("select "+name+" from "+self._prefix+type+"s_entity where guid="+str(guid))
-        name_id = self.get_metastring_id(name)
-        if name_id:
-            val_id = self.select_single("select value_id from "+self._prefix+"metadata where entity_guid="+str(guid)+" and name_id='"+str(name_id)+"'")
-            if val_id:
-                return self.get_metastring(val_id)
-        return None
-
-    # ugly
-    def get_message_fromid(self, emailid):
-        msg_id = None
-        topicid = None
-        emailid_id = self.get_metastring_id(emailid)
-        if emailid_id: 
-            msg_id = self.select_single("select entity_guid from "+self._prefix+"metadata where value_id='"+str(emailid_id)+"'")
-            topicid = self.get_relationship_inverse(msg_id, "group_discussion_top_level_post")
-            if not topicid:
-                topicid = self.get_relationship_inverse(msg_id, "group_discussion_topic_link")
-            if topicid:
-                topicid = topicid[0]
-        return msg_id, topicid
-
-    def get_entity_subtype(self, subtype, autocreate=False):
-        if not subtype:
-            return 0
-        id = self.select_single("select id from "+self._prefix+"entity_subtypes where \
-                                  subtype='%s';"%(subtype,))
-        if autocreate and not id:
-            id = self.insert("insert into "+self._prefix+"entity_subtypes (type, subtype) \
-                             values ('object','%s')"%(subtype,))
-        return id
-
-    def get_entity_subtype_name(self, subtype_id):
-        if not subtype_id:
-            return ''
-        name = self.select_single("select subtype from "+self._prefix+"entity_subtypes where \
-                                  id='%s';"%(subtype_id,))
-        return name
-
-    def get_subgroup(self, guid, name):
-        return self.select_single("select "+self._prefix+"entities.guid from "+self._prefix+"entities, "+self._prefix+"groups_entity where "+self._prefix+"entities.type='group' and "+self._prefix+"entities.container_guid="+str(guid)+" and "+self._prefix+"entities.guid = "+self._prefix+"groups_entity.guid and "+self._prefix+"groups_entity.name='"+name.replace("'","''")+"';")
-
-    def get_subgroup_names(self, guid):
-        return self.select_multi("select "+self._prefix+"groups_entity.name from "+self._prefix+"groups_entity, "+self._prefix+"entities where "+self._prefix+"entities.guid = "+self._prefix+"groups_entity.guid and "+self._prefix+"entities.type='group' and "+self._prefix+"entities.container_guid="+str(guid)+";")
-
-    def get_group_names(self):
-        return self.select_multi("select name from "+self._prefix+"groups_entity;")
-
-    def update_annotation_field(self, id, field, value):
-        return self.query("update "+self._prefix+"annotations SET %s=%s WHERE \
-                          id=%s;"%(field, value, id))
-
-    def get_annotation_data(self, id):
-        return self.select_data("select * from "+self._prefix+"annotations where id="+str(id));
-    def get_object_data(self, id):
-        return self.select_data("select * from "+self._prefix+"objects_entity where guid="+str(id))
-    def get_entity_data(self, id):
-        return self.select_data("select * from "+self._prefix+"entities where guid="+str(id))
-        return self.select_data("select * from "+self._prefix+"objects_entity where guid="+str(id))
-
-    def get_annotations(self, container_guid, subtype):
-        subtype_id = self.get_metastring_id(subtype)
-        return self.select_multi("select id from "+self._prefix+"annotations where \
-                                 entity_guid=%s and name_id=%s" %
-                                 (container_guid, subtype_id))
-
-    def get_entities_in(self, container_guid, subtype):
-        subtype_id = self.get_entity_subtype(subtype)       
-        return self.select_multi("select guid from "+self._prefix+"entities where \
-                                 container_guid=%s and subtype=%s;" %
-                                 (container_guid, subtype_id))
-
-    def get_accessid(self, guid):
-        return self.select_single("select access_id from "+self._prefix+"entities where guid=%s;"%(guid,))
-
-    def get_group_guids(self):
-        return self.select_multi("select guid from "+self._prefix+"groups_entity;")
-
-    def get_group(self, group):
-        return self.select_single("select guid from "+self._prefix+"groups_entity where \
-                                  name='%s';"%(group,))
-
-    def get_user_byemail(self, email):
-        return self.get_user(email, 'email')
-
-    def get_user(self, name, querytype='name'):
-        return self.select_single("select guid from "+self._prefix+"users_entity where \
-                                  %s='%s';"%(querytype, name))
-
-    def get_user_username(self, guid):
-        return self.select_single("select username from "+self._prefix+"users_entity where \
-                                  guid=%s;"%(guid,))
-
-    def get_user_name(self, guid):
-        return self.select_single("select name from "+self._prefix+"users_entity where \
-                                  guid=%s;"%(guid,))
-
-    def get_entity_container(self, guid):
-        return self.select_single("select container_guid from "+self._prefix+"users_entity where \
-                                  guid=%s;"%(guid,))
-
-    def get_user_email(self, guid):
-        return self.select_single("select email from "+self._prefix+"users_entity where \
-                                  guid=%s;"%(guid,))
-
-    def create_entity(self, subtype, owner_guid, group_guid, now=False,
-                      access=False, type='object'):
-        if not now:
-            now = int(time.time())
-        if not access:
-            access = ACCESS_PUBLIC
-        subtype_id = self.get_entity_subtype(subtype, True)
-        # create entity
-        obj_id = self.insert("insert into "+self._prefix+"entities (type, subtype, \
-                              owner_guid, \
-                           site_guid, container_guid, access_id, time_created, \
-                           time_updated) values ('%s', %s, %s, 1, %s, %s, \
-                                                 %s, %s);" %
-                           (type, subtype_id, owner_guid, group_guid, access, now, now));
-        return obj_id
-
-    def create_object(self, subtype, owner_guid, group_guid, title, now=False,
-                      access=False):
-        obj_id = self.create_entity(subtype, owner_guid, group_guid, now, access)
-        # object specific info
-        self.insert("insert into "+self._prefix+"objects_entity (guid, title) values (%s \
-                    ,'%s');"%(obj_id, title.replace("'","''")))
-        return obj_id
-
-    def get_metadata(self, parent_id, name):
-        name_id = self.get_metastring_id(name, True)
-        value_id = self.select_single('select value_id from '+self._prefix+'metadata where \
-                                      entity_guid=%s and \
-                                      name_id=%s'%(parent_id,name_id))
-	if value_id:
-	        return self.get_metastring(value_id)
-	else:
-		return None
-    def get_metadata_keys(self, parent_id):
-        keys = self.select_multi('select name_id from '+self._prefix+'metadata where \
-					entity_guid=%s'%(parent_id,))
-        return map(lambda id: self.get_metastring(id), keys)
-    def delete_metadata(self, parent_id, name):
-        name_id = self.get_metastring_id(name)
-        if not name_id:
-            print "no id for "+name
-            return
-        return self.query('delete from '+self._prefix+'metadata where \
-                                      entity_guid=%s and \
-                                      name_id=%s'%(parent_id,name_id))
-
-    def add_metadata(self, owner_guid, group_guid, parent_id, name, value):
-        now = int(time.time())
-        name_id = self.get_metastring_id(name, True)
-        value_id = self.get_metastring_id(str(value), True)
-        id = self.select_single('select id from '+self._prefix+'metadata where name_id=%s \
-                                and entity_guid=%s'%(name_id, parent_id))
-        if id:
-            self.query('update '+self._prefix+'metadata set value_id=%s where \
-                       id=%s'%(value_id, id))
-            return id
-        accessid = self.get_accessid(parent_id)
-        value_type = 'text'
-        if isinstance(value, int):
-            value_type = 'integer'
-        id = self.insert("insert into "+self._prefix+"metadata (entity_guid, name_id, value_id, \
-                    value_type, owner_guid, access_id, time_created) \
-            values(%s, %s, %s, '%s', %s, %s, %s);" % (parent_id, name_id,
-                                                       value_id, value_type,
-                                                       owner_guid, accessid, now))
-        return id
-
-    def create_grouptopic(self, owner_guid, group_guid, topic):
-        status_id = self.get_metastring_id('status')
-        open_id = self.get_metastring_id('open')
-        now = int(time.time())
-        accessid = self.get_accessid(group_guid)
-        topicid = self.create_object('groupforumtopic', owner_guid, group_guid,
-                                    topic, access = accessid)
-        # insert status metadata
-        self.insert("insert into "+self._prefix+"metadata (entity_guid, name_id, value_id, \
-                    value_type, owner_guid, access_id, time_created) \
-            values(%s, %s, %s, 'text', %s, %s, %s);" % (topicid, status_id,
-                                                       open_id, owner_guid, accessid, now))
-        #self.add_to_river('object', 'groupforumtopic', 'create',
-        #                  'river/forum/topic/create', owner_guid, topicid)
-        return topicid
-
-    def create_topicmessage(self, topicid, message, owner_guid, group_id,
-                            encrypted=False,addtoriver='river/forum/create',email_id=None):
-        now = int(time.time())
-        topic_id = self.get_metastring_id('group_topic_post')
-        message_id = self.get_metastring_id(message, True)
-        comment_parent = topicid
-        accessid = self.get_accessid(topicid)
-        self.add_relationship(group_id, 'group_discussion',
-                                  topicid)
-        if self.threaded_forums:
-            post_id = self.create_entity('groupforumpost', owner_guid, group_id, access=accessid)
-            self.add_relationship(topicid, 'group_discussion_top_level_post',
-                                  post_id)
-            comment_parent = post_id
-            if encrypted:
-                self.add_metadata(owner_guid, group_id, post_id, 'encrypted', 1)
-            self.add_metadata(owner_guid, group_id, post_id, 'message_id', email_id)
-        comment_id = self.insert("insert into "+self._prefix+"annotations (entity_guid, name_id, \
-                           value_id, value_type, owner_guid, access_id, \
-                           time_created) values (%s, %s, %s, 'text', %s, \
-                          %s, %s);" %(comment_parent, topic_id, message_id, owner_guid, accessid, now))
-        if addtoriver:
-            self.add_to_river('object', 'groupforumtopic', 'create',
-                          addtoriver, owner_guid, topicid, comment_id)
-        if self.threaded_forums:
-            return post_id
-        else:
-            return comment_id
-    def create_topicmessage_response(self, topicid, message, owner_guid,
-                                     group_id, orig_id, encrypted=False, email_id=None):
-        now = int(time.time())
-        topic_id = self.get_metastring_id('group_topic_post')
-        message_id = self.get_metastring_id(message, True)
-        accessid = self.get_accessid(topicid)
-        if self.threaded_forums:
-            post_id = self.create_entity('groupforumpost', owner_guid, group_id, access=accessid)
-            if encrypted:
-                self.add_metadata(owner_guid, group_id, post_id, 'encrypted', 1)
-            query = "insert into "+self._prefix+"annotations (entity_guid, name_id, \
-                           value_id, value_type, owner_guid, access_id, \
-                           time_created) values (%s, %s, %s, 'text', %s, \
-                          %s, %s);" %(post_id, topic_id, message_id, owner_guid, accessid, now)
-
-            comment_id = self.insert("insert into "+self._prefix+"annotations (entity_guid, name_id, \
-                           value_id, value_type, owner_guid, access_id, \
-                           time_created) values (%s, %s, %s, 'text', %s, \
-                          %s, %s);" %(post_id, topic_id, message_id, owner_guid, accessid, now))
-            self.add_relationship(topicid, 'group_discussion_topic_link',
-                                  post_id)
-            self.add_relationship(orig_id, 'group_discussion_reply_post',
-                                  post_id)
-            self.add_metadata(owner_guid, group_id, post_id, 'message_id', email_id)
-            self.add_to_river('object', 'groupforumtopic', 'create',
-                          'river/forum/create', owner_guid, topicid, comment_id)
-            return post_id
-        else:
-            return self.create_topicmessage(topicid, message, owner_guid)
-
-if __name__ == "__main__":
-    elgg = ElggConnect('localhost', 'caedes', 'xxxxxxxx', 'n1')
-    # get some data
-    groupid = elgg.get_group('darkwave')
-    userid = elgg.get_user_byemail('caedes@foo.org')
-    print "user:"+str(userid)
-    topicid = elgg.create_grouptopic(userid, groupid, "python injection")
-    id = elgg.create_topicmessage(topicid, "inserted with python code!!", userid,
-                             groupid)
-    id2 = elgg.create_topicmessage_response(topicid, "inserted with python code!!", userid,
-                             groupid, id)
-    users = elgg.get_relationship_inverse(groupid, 'notifymailshot')
-    elgg.add_metadata(userid, groupid, id2, 'encrypted', 1)
-    usernames = map(elgg.get_user_email, users)
-    #elgg.add_relationship(userid, 'notifymailshot', groupid)
-    print usernames
-
-# create group topic
-
-