def add_attributes_to_edgelist(db, edgelist, edge_key, message_id, edge_attribute_names, source='maildir'): """Given an existing edgelist, a message to pull attributes from, the names in the database of the attributes to be pulled, and the source of the emails, query the db and add the requested attributes to the edgelist. """ cursor = find_emails(db, source=source, message_id=message_id) email = cursor.next() # Only get one email -- others should be dups for edge_attribute_name in edge_attribute_names: this_attribute = email[edge_attribute_name] #print edge_attribute_name, this_attribute if edge_attribute_name in edgelist[edge_key]: edgelist[edge_key][edge_attribute_name].append(this_attribute) else: edgelist[edge_key][edge_attribute_name] = [this_attribute]
#!/usr/bin/env python from arbre.database import init_dbconn from arbreapp.mailman.queries import find_emails, find_communications ### Some basics on querying # We first initialize our database connection db = init_dbconn() # count=0 means no limit on query size # cursor = find_emails(source='lucene', count=0) cursor = find_emails(db, source='maildir') # defaults to limit of 50 emails senders = list() for email in cursor: if 'to' in email and 'ffrom' in email: senders.append((email['to'], email['ffrom'])) print 'An example list:\n%s\n' % (senders) ### Generating the list of recipients between 1/1/2001 and 1/5/2001 start_datetext = "January 1, 2001" end_datetext = "1/5/2001" cursor = find_communications(db, source='maildir', start_date=start_datetext, end_date=end_datetext) early_january_recips = [email['to'] for email in cursor] print 'Recipients of email between %s and %s:' % (start_datetext, end_datetext) print early_january_recips print ''