def get_snippets_from_person(me, top_emailer): all_snippets_from_person = [] for filename in os.listdir(args.emails_path): e1 = email_lib.read_email(args.emails_path + filename) if is_email_valid(e1, me, top_emailer): for snippet in get_snippets(e1, top_emailer): snippet.filename = filename all_snippets_from_person.append(snippet) # Randomly select N snippets random.shuffle(all_snippets_from_person) if args.num_snippets <= len(all_snippets_from_person): some_snippets = all_snippets_from_person[0:args.num_snippets] else: print "Not enough snippets." some_snippets = all_snippets_from_person return some_snippets
def read_all_files(path): emails = [] for filename in os.listdir(path): emails.append(email_lib.read_email(path + filename)) return emails
from collections import Counter parser = argparse.ArgumentParser(description='Find the top N people that ' + \ 'you email most frequently.') # It's important to have your email address because you want to add a name to # the "top emailers" if they directly email with you (e.g. no mailing lists). parser.add_argument('your_email', help='your email address') parser.add_argument('-p', '--emails_path', default='processed_emails/', help='the path to the directory with all the emails') parser.add_argument('-n', '--num_people', type=int, default=20, help='the number of people to get') args = parser.parse_args() top_people = Counter() for filename in os.listdir(args.emails_path): e1 = email_lib.read_email(args.emails_path + filename) if args.your_email == e1.from_address: for to_address in e1.to_addresses: top_people[to_address] += 1 # if you're in the from and the to, don't add yourself twice elif args.your_email in e1.to_addresses: top_people[e1.from_address] += 1 for person, count in top_people.most_common(args.num_people): print person + ', ' + str(count)