Пример #1
0
    def update_ticketholders_list(self):
        ms = MailSnake(app.config['MAILCHIMP_KEY'])
        list_id = '5f939ca32a'  # Ticketholders 2016
        tix = Ticket.query.filter_by(paid=True).join(User).\
            group_by(User).with_entities(User).order_by(User.id)

        list_members = {
            member['email']
            for member in ms.listMembers(id=list_id, limit=10000)['data']
        }
        current_users = {ticket.email for ticket in tix}

        to_remove = list_members - current_users
        to_add = current_users - list_members

        app.logger.info(
            "Ticketholders list: adding %s addresses, removing %s addresses",
            len(to_add), len(to_remove))

        res = ms.listBatchUnsubscribe(id=list_id,
                                      emails=list(to_remove),
                                      send_goodbye=False)
        print(res)

        to_add_data = [{
            'EMAIL': email,
            'EMAIL_TYPE': 'html'
        } for email in to_add]
        res = ms.listBatchSubscribe(id=list_id,
                                    batch=to_add_data,
                                    double_optin=False,
                                    update_existing=True)
        print(res)
Пример #2
0
    def update_ticketholders_list(self):
        ms = MailSnake(app.config['MAILCHIMP_KEY'])
        list_id = '5f939ca32a'  # Ticketholders 2016
        tix = Ticket.query.filter_by(paid=True).join(User).\
            group_by(User).with_entities(User).order_by(User.id)

        list_members = {member['email'] for member in ms.listMembers(id=list_id, limit=10000)['data']}
        current_users = {ticket.email for ticket in tix}

        to_remove = list_members - current_users
        to_add = current_users - list_members

        app.logger.info("Ticketholders list: adding %s addresses, removing %s addresses",
                        len(to_add), len(to_remove))

        res = ms.listBatchUnsubscribe(id=list_id, emails=list(to_remove), send_goodbye=False)
        print(res)

        to_add_data = [{'EMAIL': email, 'EMAIL_TYPE': 'html'} for email in to_add]
        res = ms.listBatchSubscribe(id=list_id, batch=to_add_data,
                                    double_optin=False, update_existing=True)
        print(res)
    int(os.getenv('last_sync_stamp',
                  datetime(2013, 06, 25).strftime('%s'))))

date_format = '%m/%d/%Y %X'

signedup_recently = [
    user['email'] for user in signedup_on_firebase.values()
    if datetime.strptime(user['submit_time'], date_format) > last_pull_datetime
]

for e in signedup_recently:
    email = {'EMAIL': e}
    batches.append(email)

try:
    ms.listBatchSubscribe(id='d7bce2ac5d', batch=batches,
                          double_optin=False)  # returns "Everything's Chimpy!"
    ms.listBatchSubscribe(id='b83180baa4', batch=batches,
                          double_optin=False)  # returns "Everything's Chimpy!"
    mailchimp_worked = True
except MailSnakeException:
    print 'An error occurred. :('

#{u'email': u'*****@*****.**', u'location': u', ', u'submit_time': u'06/07/2013 19:07:26'}

# TODO Send to mailchimp here then set variable to true
print batches

if mailchimp_worked:
    print "Ran successfully at {}".format(datetime.now())
    print "{} emails since last time".format(len(signedup_recently))
    os.putenv('last_sync_stamp', datetime.now().strtime('%s'))