Beispiel #1
0
def insert_topic_category(conn, category_id, idx, value, score, purity, docs):
    stmt = (
        "insert into topic_category (category_id, idx, value, score, purity, docs) "
        " values (%s, %s, %s, %s, %s, %s)")
    with execute_nonquery(conn, stmt, category_id, idx, value, score, purity,
                          docs) as qry:
        pass
Beispiel #2
0
def setExportable(data):
    email = data.get('email', None)
    exportable = data.get('exportable', 'false')

    if not email:
        tangelo.content_type("application/json")
        stmt = (" UPDATE email SET exportable='false' ")
        with newman_connector() as read_cnx:
            with execute_nonquery(read_cnx.conn(), stmt) as qry:
                return {"success": "true"}
        #return tangelo.HTTPStatusCode(400, "invalid service call - missing id")

    tangelo.content_type("application/json")
    stmt = (" UPDATE email SET exportable= %s WHERE id = %s ")
    with newman_connector() as read_cnx:
        with execute_nonquery(read_cnx.conn(), stmt, exportable, email) as qry:
            return {"email": queryEmail(email)}
Beispiel #3
0
def setExportMany(data):
    emails = data.get('emails', [])
    exportable = 'true' if data.get('exportable', True) else 'false'
    stmt = (" UPDATE email SET exportable=%s WHERE id = %s ")
    with newman_connector() as cnx:
        for email in emails:
            with execute_nonquery(cnx.conn(), stmt, exportable, email) as qry:
                pass
    tangelo.content_type("application/json")
    return {'exported': emails}
Beispiel #4
0
def setExportMany(data):
    emails = data.get('emails', [])
    exportable= 'true' if data.get('exportable', True) else 'false'
    stmt = (
        " UPDATE email SET exportable=%s WHERE id = %s "	
    )
    with newman_connector() as cnx:
        for email in emails: 
            with execute_nonquery(cnx.conn(), stmt, exportable, email) as qry:
                pass
    tangelo.content_type("application/json")
    return { 'exported' : emails }
Beispiel #5
0
def setExportable(data):
    email = data.get('email', None)
    exportable = data.get('exportable', 'false')

    if not email:
        tangelo.content_type("application/json")
        stmt = (
            " UPDATE email SET exportable='false' "	
        )
        with newman_connector() as read_cnx:
            with execute_nonquery(read_cnx.conn(), stmt) as qry:
                return { "success" : "true" }
        #return tangelo.HTTPStatusCode(400, "invalid service call - missing id")
    
    tangelo.content_type("application/json")
    stmt = (
        " UPDATE email SET exportable= %s WHERE id = %s "	
    )
    with newman_connector() as read_cnx:
        with execute_nonquery(read_cnx.conn(), stmt, exportable, email ) as qry:
            return { "email" : queryEmail(email) }
Beispiel #6
0
    def addEmail(self, id, threadid, dir, category, datetime, from_addr, tos, ccs, bccs, subject, body, tosize, ccsize, bccsize, attachsize, attach, bodysize, location, line_num):

        stmt = ("insert into email " 
                "(id, threadid, dir, category, datetime, from_addr, tos, "
                "ccs, bccs, subject, body, tosize, ccsize, bccsize, attachsize, "
                "attach, bodysize, location, line_num) " 
                "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,"
                " %s, %s, %s, %s, %s, %s, %s, %s, %s)")
        
        with execute_nonquery(self.conn, stmt, id, threadid, dir, category, datetime, 
                              from_addr, tos, ccs, bccs, subject, body, tosize, ccsize, 
                              bccsize, attachsize, attach, bodysize, location, line_num) as insert:
            pass
Beispiel #7
0
        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        facts = Fact(write_cnx.conn(), autocommit=False)
        print "assigning communities"
        for node in nodes:
            email_addr, community_id = node['name'], node['community']
            facts.addFact(email_addr, "email_addr", "community", community_id,
                          txid)
            facts.addFact(email_addr, "email_addr", "group_id", next(count),
                          txid)

        print "commit"
        write_cnx.commit()

        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        print "assign community ids"
        stmt = (
            " insert into facts (subject, schema_name, predicate, obj, tx) "
            " select f.subject, f.schema_name, 'community_id', f2.obj, %s "
            " from facts f join facts f2 on f.obj = f2.subject "
            " where f.schema_name = 'email_addr' "
            " and f.predicate = 'community' "
            " and f2.schema_name = f.schema_name and f2.predicate = 'group_id' "
        )

        with execute_nonquery(write_cnx.conn(), stmt, txid) as qry:
            pass
        print "commit"
        write_cnx.commit()
    " and f.predicate = 'from'"
    " and f2.predicate in ('to', 'cc', 'bcc')"
)

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='Enrich Emails Communications')
    args= parser.parse_args()

    with newman_connector() as read_cnx, newman_connector() as write_cnx:
        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        print "enrich sent to recipient communications"
        facts = Fact(write_cnx.conn(), autocommit=False)
        
        with execute_nonquery(write_cnx.conn(), stmt_sent_to, txid) as qry:
            pass
        write_cnx.commit()
    
        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        print "enrich total sent to " 
        with execute_query(write_cnx.conn(), stmt_total_recipients, txid) as qry:
            pass
        write_cnx.commit()
    
        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        print "enrich total received "
        with execute_query(write_cnx.conn(), stmt_total_received, txid) as qry:
            pass
Beispiel #9
0
    def addText(self, subject, object, tx):
        stmt = ("insert into large_text (subject, obj, tx) values (%s, %s, %s)")

        with execute_nonquery(self.conn, stmt, subject.lower(), object, tx, **{ 'autocommit': self.autocommit }) as insert: 
            pass
Beispiel #10
0
 def addFact(self, subject, schema, predicate, object, tx):
     stmt = "insert into facts (subject, schema_name, predicate, obj, tx) values (%s, %s, %s, %s, %s)"
     with execute_nonquery(self.conn, stmt, subject.lower(), schema.lower(), predicate.lower(), object, tx, **{ 'autocommit': self.autocommit }) as insert: 
         pass
Beispiel #11
0
 def next(self):
     with execute_nonquery(self.conn, 'insert into tx () values ()') as qry:
         tx = qry.cursor().getlastrowid()
         return tx
Beispiel #12
0
    " on x.entity_id = e.subject ")

stmt_xref_email_community = (
    " insert into xref_email_community (email_id, community_id) "
    " select distinct e.id, a.community_id "
    " from email e join xref_emailaddr_email x on e.id = x.email_id "
    " join email_addr a on x.email_addr = a.email_addr ")

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='Post Process')
    args = parser.parse_args()

    with newman_connector() as write_cnx:
        print "populate email_addr"
        with execute_nonquery(write_cnx.conn(), stmt_email_addr_insert) as qry:
            pass
        write_cnx.commit()

        print "populate xref_emailaddr_email"
        with execute_nonquery(write_cnx.conn(),
                              stmt_xref_emailaddr_email) as qry:
            pass
        write_cnx.commit()

        print "populate xref_entity_email"
        with execute_nonquery(write_cnx.conn(), stmt_xref_entity_email) as qry:
            pass
        write_cnx.commit()

        print "populate xref_email_community"
Beispiel #13
0
stmt_xref_email_community = (
    " insert into xref_email_community (email_id, community_id) "
    " select distinct e.id, a.community_id "
    " from email e join xref_emailaddr_email x on e.id = x.email_id " 
    " join email_addr a on x.email_addr = a.email_addr "
)

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='Post Process')
    args= parser.parse_args()

    with newman_connector() as write_cnx:
        print "populate email_addr"
        with execute_nonquery(write_cnx.conn(), stmt_email_addr_insert) as qry:
            pass
        write_cnx.commit()

        print "populate xref_emailaddr_email"
        with execute_nonquery(write_cnx.conn(), stmt_xref_emailaddr_email) as qry:
            pass
        write_cnx.commit()

        print "populate xref_entity_email"
        with execute_nonquery(write_cnx.conn(), stmt_xref_entity_email) as qry:
            pass
        write_cnx.commit()
        
        print "populate xref_email_community"
        with execute_nonquery(write_cnx.conn(), stmt_xref_email_community) as qry:
def insert_topic_category(conn, category_id, idx, value, score, purity, docs):
    stmt = ("insert into topic_category (category_id, idx, value, score, purity, docs) "
            " values (%s, %s, %s, %s, %s, %s)")
    with execute_nonquery(conn, stmt, category_id, idx, value, score, purity, docs) as qry:
        pass