Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (52 sloc) 2.02 KB
# user/bin/env python3
# - réconcilier les listes d'e-mails.
from mailchimp3 import MailChimp
from [–] import apiKey
userName = '[–]'
mcClient = MailChimp(apiKey, userName)
# find list that pertains to subscribers/members
mcClient.lists.all(get_all=True, fields=",")
# {'total_items': 2, 'lists': [{'name': 'General', 'id': '101'}, {'name': 'Media', 'id': '102'}]}
memberInfo = mcClient.lists.members.all(list_id='101', get_all=True, fields="members.email_address,")
sourceData = members['members']
emailMaster = []
for entry in sourceData:
# Use emailMaster as variable for list of all e-mails for subscribers.
from import sql
from sqlalchemy import create_engine, MetaData, Table, select
import pandas as pd
import pymysql
ServerName = '[–]'
Database = '[–]'
engine = create_engine('mysql://' + ServerName + '/' + Database)
conn = engine.connect()
metadata = MetaData(conn)
TableName = '[–]'
with engine.connect() as conn, conn.begin():
df = pd.read_sql_table(TableName, conn)
# Use userEmails as variable for list of all e-mails in the Wordpress user table.
userEmails = df['user_email'].unique().tolist()
lowerUser = [x.lower() for x in userEmails]
lowerMaster = [x.lower() for x in emailMaster]
migrateEmails = []
for entry in lowerUser:
if entry not in lowerMaster:
print(' ')
print('The following e-mails exist in Wordpress that need to be added to the members list in Mailchimp :')
# Remember, 'General' Mailchimp list for subscribers is : list_id='101'
for entry in migrateEmails:
mcClient.lists.members.create('101', {
'email_address': entry,
'status': 'subscribed',
print(' ')
if migrateEmails:
print('These e-mails have been migrated into Mailchimp for you. Thank you.')
print('There were no e-mails to migrate. Please check back later. Thank you.')
print(' ')