def test_minus_old_emails(self, load_file): n = ActionNetwork() n.load() old_data = [{ 'first_name': 'Henry', 'last_name': 'Kissinger', 'email': '*****@*****.**' }, { 'zip': '01234', 'ward_precinct': 'MA1', 'email': '*****@*****.**', 'first_name': 'Libby', 'last_name': 'Snowflake', 'vanid': '999' }] # Libby Snowflake exists in the old data and the new. Expect to see only her. combed = n.minus_email_matches(other_data=old_data) self.assertEqual([{ 'ward_precinct': 'MA2', 'zip': '02345', 'last_name': 'Provocateur', 'vanid': '888', 'event': 'boxing match', 'email': '*****@*****.**', 'first_name': 'Agent' }], combed)
def test_only_old_emails(self, load_file): n = ActionNetwork() n.load() old_data = [{ 'first_name': 'Henry', 'last_name': 'Kissinger', 'email': '*****@*****.**' }, { 'zip': '01234', 'ward_precinct': 'MA1', 'email': '*****@*****.**', 'first_name': 'Libby', 'last_name': 'Snowflake', 'vanid': '999' }] # Libby Snowflake exists in the old data and the new. Expect to see her gone. combed = n.only_email_matches(other_data=old_data) self.assertEqual([{ 'vanid': '999', 'last_name': 'Snowflake', 'zip': '01234', 'event': 'ice cream social', 'ward_precinct': 'MA1', 'first_name': 'Libby', 'email': '*****@*****.**' }], combed)
def test_to_csv(self, load_file): n = ActionNetwork() n.load() csv = n.to_csv() self.assertEqual( "first_name,last_name,email,zip_code,ORMA Supporter,VoterVANID,Ward/PrecinctName,Zip\r\nLibby,Snowflake,[email protected],01234,,999,MA1,\r\nAgent,Provocateur,[email protected],02345,,888,MA2,\r\n", csv)
def test_load(self, load_file): n = ActionNetwork() n.load() self.assertEqual([{ 'zip': '01234', 'ward_precinct': 'MA1', 'email': '*****@*****.**', 'first_name': 'Libby', 'last_name': 'Snowflake', 'vanid': '999', 'event': 'ice cream social' }, { 'zip': '02345', 'ward_precinct': 'MA2', 'email': '*****@*****.**', 'first_name': 'Agent', 'last_name': 'Provocateur', 'vanid': '888', 'event': 'boxing match' }], n.rows)
""" generates count of records for each "Event" type """ from objects.ActionNetwork import ActionNetwork from collections import OrderedDict import operator a = ActionNetwork() a.load() events = {} for row in a.rows: event = str(row['event']).strip() if event not in events: events[event] = 0 events[event] += 1 events = OrderedDict( sorted(events.items(), key=operator.itemgetter(1), reverse=True)) [print(row, ':', count) for row, count in events.items()]