def dump_old_data(): sequences = [("1", "bqtde"), ("2", "br67o"), ("3", "brmcg")] user_keys = ["email", "created_at", "group_id", "group_size"] event_keys = ["event", "timestamp", "tags", "link"] for sequence, campaign_id in sequences: writer = unicodecsv.writer(open("sequence_{0}_all.csv".format(sequence), "w")) users = old_sequence_users(sequence) for user in users: user["group_size"] = 0 if user["group_id"]: user["group_size"] = len([u for u in users if u["group_id"] == user["group_id"]]) sequence_data = [] for i, user in enumerate(users): print("getting data for user {0} of {1}: {2}".format(i, len(users), user["email"])) get_stats = lambda p: mailgun_api.get_campaign_events( campaign_id, ["opened", "clicked"], recipient=user["email"], page=p ) user_stats = _fetch_all(get_stats) for event in user_stats: if "link" not in event: event["link"] = "" event["tags"] = str(event["tags"]) row = [user[key] for key in user_keys] row += [event[key] for key in event_keys] writer.writerow(row)
def dump_data(): sequences = [(4, 'sequence_4_campaign')] user_keys = ['email', 'date_created', 'group_id', 'group_size'] event_keys = ['event', 'timestamp', 'tags', 'link'] for sequence, campaign_id in sequences: writer = unicodecsv.writer(open('sequence_{0}_all.csv'.format(sequence), 'w')) writer.writerow(user_keys + event_keys + ['control_group']) users = signup_api.get_signups(sequence) for user in users: user['group_size'] = 0 user['group_id'] = None user_groups = groups_api.get_member_groups(user['email']) if len(user_groups) == 1: user['group_id'] = user_groups[0]['address'] user['group_size'] = len(user_groups[0]['members']) user['control_group'] = user['group_id'] in settings.EXPERIMENTAL_GROUPS sequence_data = [] for i, user in enumerate(users): print('getting data for user {0} of {1}: {2}'.format(i,len(users),user['email'])) get_stats = lambda p: mailgun_api.get_campaign_events(campaign_id, ['opened', 'clicked'], recipient=user['email'], page=p) user_stats = _fetch_all(get_stats) for event in user_stats: if 'link' not in event: event['link'] = '' event['tags'] = str(event['tags']) row = [ user[key] for key in user_keys ] row += [ event[key] for key in event_keys ] row += [ user['control_group'] ] writer.writerow(row)
def dump_old_data(): sequences = [('1', 'bqtde'), ('2', 'br67o'), ('3', 'brmcg')] user_keys = ['email', 'created_at', 'group_id', 'group_size'] event_keys = ['event', 'timestamp', 'tags', 'link'] for sequence, campaign_id in sequences: writer = unicodecsv.writer( open('sequence_{0}_all.csv'.format(sequence), 'w')) users = old_sequence_users(sequence) for user in users: user['group_size'] = 0 if user['group_id']: user['group_size'] = len( [u for u in users if u['group_id'] == user['group_id']]) sequence_data = [] for i, user in enumerate(users): print('getting data for user {0} of {1}: {2}'.format( i, len(users), user['email'])) get_stats = lambda p: mailgun_api.get_campaign_events( campaign_id, ['opened', 'clicked'], recipient=user['email'], page=p) user_stats = _fetch_all(get_stats) for event in user_stats: if 'link' not in event: event['link'] = '' event['tags'] = str(event['tags']) row = [user[key] for key in user_keys] row += [event[key] for key in event_keys] writer.writerow(row)
def dump_old_data(): sequences = [('1', 'bqtde'), ('2', 'br67o'), ('3','brmcg')] user_keys = ['email', 'created_at', 'group_id', 'group_size'] event_keys = ['event', 'timestamp', 'tags', 'link'] for sequence, campaign_id in sequences: writer = unicodecsv.writer(open('sequence_{0}_all.csv'.format(sequence), 'w')) users = old_sequence_users(sequence) for user in users: user['group_size'] = 0 if user['group_id']: user['group_size'] = len([u for u in users if u['group_id'] == user['group_id']]) sequence_data = [] for i, user in enumerate(users): print('getting data for user {0} of {1}: {2}'.format(i,len(users),user['email'])) get_stats = lambda p: mailgun_api.get_campaign_events(campaign_id, ['opened', 'clicked'], recipient=user['email'], page=p) user_stats = _fetch_all(get_stats) for event in user_stats: if 'link' not in event: event['link'] = '' event['tags'] = str(event['tags']) row = [ user[key] for key in user_keys ] row += [ event[key] for key in event_keys ] writer.writerow(row)
def dump_data(prefix=''): sequences = [(4, 'sequence_4_campaign'), (5, 'sequence_5_campaign')] #sequences = [(1, 'sequence_1_campaign')] user_keys = ['email', 'date_created', 'group_id', 'group_size'] event_keys = ['event', 'timestamp', 'tags', 'link'] for sequence, campaign_id in sequences: users = signup_api.get_signups_for_archiving(sequence) for user in users: user['group_size'] = 0 user['group_id'] = None user_groups = groups_api.get_member_groups(user['email']) if len(user_groups) == 1: user['group_id'] = user_groups[0]['address'] user['group_size'] = len(user_groups[0]['members']) user.update(user['questions']) del user['questions'] # open file for writing data timestamp = datetime.now().date().isoformat() filename = '_'.join( [prefix, 'sequence', str(sequence), 'users', timestamp]).strip('_') + '.csv' write_to_csv(users, filename) filename = '_'.join( [prefix, 'sequence', str(sequence), 'events', timestamp]).strip('_') + '.csv' writer = unicodecsv.writer(open(filename, 'w')) writer.writerow(user_keys + event_keys) sequence_data = [] for i, user in enumerate(users): print('getting data for user {0} of {1}: {2}'.format( i, len(users), user['email'])) get_stats = lambda p: mailgun_api.get_campaign_events( campaign_id, ['opened', 'clicked'], recipient=user['email'], page=p) user_stats = _fetch_all(get_stats) for event in user_stats: if 'link' not in event: event['link'] = '' event['tags'] = str(event['tags']) row = [user[key] for key in user_keys] row += [event[key] for key in event_keys] writer.writerow(row) export_emails('_'.join([prefix, 'sequence', str(sequence)]).strip('_'))
def dump_data(prefix=''): sequences = [(4, 'sequence_4_campaign'), (5, 'sequence_5_campaign')] #sequences = [(1, 'sequence_1_campaign')] user_keys = ['email', 'date_created', 'group_id', 'group_size'] event_keys = ['event', 'timestamp', 'tags', 'link'] for sequence, campaign_id in sequences: users = signup_api.get_signups_for_archiving(sequence) for user in users: user['group_size'] = 0 user['group_id'] = None user_groups = groups_api.get_member_groups(user['email']) if len(user_groups) == 1: user['group_id'] = user_groups[0]['address'] user['group_size'] = len(user_groups[0]['members']) user.update(user['questions']) del user['questions'] # open file for writing data timestamp = datetime.now().date().isoformat() filename = '_'.join([prefix, 'sequence', str(sequence), 'users', timestamp]).strip('_') + '.csv' write_to_csv(users, filename) filename = '_'.join([prefix, 'sequence', str(sequence), 'events', timestamp]).strip('_') + '.csv' writer = unicodecsv.writer(open(filename, 'w')) writer.writerow(user_keys + event_keys) sequence_data = [] for i, user in enumerate(users): print('getting data for user {0} of {1}: {2}'.format(i,len(users),user['email'])) get_stats = lambda p: mailgun_api.get_campaign_events(campaign_id, ['opened', 'clicked'], recipient=user['email'], page=p) user_stats = _fetch_all(get_stats) for event in user_stats: if 'link' not in event: event['link'] = '' event['tags'] = str(event['tags']) row = [ user[key] for key in user_keys ] row += [ event[key] for key in event_keys ] writer.writerow(row) export_emails('_'.join([prefix, 'sequence', str(sequence)]).strip('_'))
def dump_data(): sequences = [(4, "sequence_4_campaign")] user_keys = ["email", "date_created", "group_id", "group_size"] event_keys = ["event", "timestamp", "tags", "link"] for sequence, campaign_id in sequences: writer = unicodecsv.writer(open("sequence_{0}_all.csv".format(sequence), "w")) writer.writerow(user_keys + event_keys + ["control_group"]) users = signup_api.get_signups(sequence) for user in users: user["group_size"] = 0 user["group_id"] = None user_groups = groups_api.get_member_groups(user["email"]) if len(user_groups) == 1: user["group_id"] = user_groups[0]["address"] user["group_size"] = len(user_groups[0]["members"]) user["control_group"] = user["group_id"] in settings.EXPERIMENTAL_GROUPS sequence_data = [] for i, user in enumerate(users): print("getting data for user {0} of {1}: {2}".format(i, len(users), user["email"])) get_stats = lambda p: mailgun_api.get_campaign_events( campaign_id, ["opened", "clicked"], recipient=user["email"], page=p ) user_stats = _fetch_all(get_stats) for event in user_stats: if "link" not in event: event["link"] = "" event["tags"] = str(event["tags"]) row = [user[key] for key in user_keys] row += [event[key] for key in event_keys] row += [user["control_group"]] writer.writerow(row)