예제 #1
0
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)
예제 #2
0
    def test_get_member_groups(self):
        group = group_model.create_group('*****@*****.**', 'The A team', 1)
        group_model.add_group_member(group['uri'], '*****@*****.**')

        group = group_model.get_group(group['uri'])
        groups = group_model.get_member_groups('*****@*****.**')

        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0], group)
예제 #3
0
    def test_get_member_groups(self):
        group = group_model.create_group('*****@*****.**', 'The A team', 1)
        group_model.add_group_member(group['uri'], '*****@*****.**')
        
        group = group_model.get_group(group['uri'])
        groups = group_model.get_member_groups('*****@*****.**')

        self.assertEqual(len(groups), 1)
        self.assertEqual(groups[0], group)
예제 #4
0
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('_'))
예제 #5
0
def unsubscribe_from_sequence( address ):

    # remove from sequence group
    try:
        user_signup = signup_model.get_signup(address)
        sequence_list = sequence_model.sequence_list_name(user_signup['sequence'])
        mailgun_api.remove_list_member(sequence_list, address)
    except:
        log.error(u"couldn't remove {0} from sequence list".format(address))
    
    # remove from small groups
    # TODO: Can a user be subscribed to more than one group or more than one
    # sequence at the same time?
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group['uri'], address)
        groups_model.sync_group_with_mailgun(group['uri'])

    # add signup to next sequence.
    signup_model.remove_signup_from_sequence(address)
예제 #6
0
def unsubscribe_user( address ):
    """ Unsubscribe user completely from the Mechanical Mooc 
    """

    # remove from sequence group
    try:
        user_signup = signup_model.get_signup(address)
        sequence_list = sequence_model.sequence_list_name(user_signup['sequence'])
        mailgun_api.remove_list_member(sequence_list, address)
    except:
        log.error(u"couldn't remove {0} from sequence list".format(address))

    # remove from small groups
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group['uri'], address)
        groups_model.sync_group_with_mailgun(group['uri'])

    # mark as unsubscribed in the signups
    signup_model.delete_signup(address)
예제 #7
0
def unsubscribe_user(address):
    """ Unsubscribe user completely from the Mechanical Mooc - all sequences
    """

    # remove from sequence group
    signups = signup_model.get_all_user_signups(address)
    for user_signup in signups:
        sequence_list = sequence_model.sequence_list_name(user_signup["sequence"])
        mailgun_api.remove_list_member(sequence_list, address)

    # remove from small groups
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group["uri"], address)
        groups_model.sync_group_with_mailgun(group["uri"])

    # mark as unsubscribed in the signups
    for user_signup in signups:
        signup_model.delete_signup(address, user_signup["sequence"])

    mailgun_api.delete_all_unsubscribes(address)
예제 #8
0
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('_'))
예제 #9
0
def unsubscribe_user(address):
    """ Unsubscribe user completely from the Mechanical Mooc - all sequences
    """

    # remove from sequence group
    signups = signup_model.get_all_user_signups(address)
    for user_signup in signups:
        sequence_list = sequence_model.sequence_list_name(
            user_signup['sequence'])
        mailgun_api.remove_list_member(sequence_list, address)

    # remove from small groups
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group['uri'], address)
        groups_model.sync_group_with_mailgun(group['uri'])

    # mark as unsubscribed in the signups
    for user_signup in signups:
        signup_model.delete_signup(address, user_signup['sequence'])

    mailgun_api.delete_all_unsubscribes(address)
예제 #10
0
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)