Пример #1
0
def create2():
    type = 'regular'
    options = {
        'list_id': request.form['emailList'],
        'subject': request.form['subject'],
        'from_email': request.form['outgoinEmail'],
        'from_name': request.form['outgoinName'],
        'title': request.form['campaignName'],
        'auto_footer': False,
        'folder_id': request.form['folder']
    }
    content = {'html': request.form['html']}
    # se quita como ya no existen eventos
    # event_id = int(request.form['event_id'])
    # if (event_id > 0):
    #     event_data = get_event_data(event_id)
    #     content = {
    #         'html': replace_tags(request.form['html'], event_data)
    #     }
    m = get_mailchimp_api()
    try:
        if 'id' in request.form:
            cid = request.form['id']
            detailsVar = m.campaigns.update(cid, 'options', options)
            details2 = m.campaigns.update(cid, 'content', content)
            errors = detailsVar['errors']
            detailsVar = detailsVar['data']
        else:
            detailsVar = m.campaigns.create(type, options, content)
    except mailchimp.Error, e:
        return index("<div class='alert alert-danger'>Ha ocurrido un error \
                      con mailchimp " + str(e) + "</div>")
Пример #2
0
def index(message=None):
    try:
        m = get_mailchimp_api()
        lists = m.lists.list(limit=100)

    except mailchimp.Error, e:
        return "Ha ocurrido un error al intentar conectar con mailchimp"
Пример #3
0
def send():
    id_ = request.form['id']
    try:
        m = get_mailchimp_api()
        status = m.campaigns.send(id_)
    except mailchimp.Error, e:
        flash("Se encontraron errores con mailchimp " + str(e), "error")
Пример #4
0
def statistics():
    m = get_mailchimp_api()
    data = {'mailing_count': m.campaigns.list(limit=0).get('total', 0),
            'template_count': len(m.templates.list().get('user')),
            'emails_list_count': m.lists.list(limit=0).get('total', 0)
            }
    return json.dumps(data)
Пример #5
0
def create():
    try:
        m = get_mailchimp_api()
        lists = m.lists.list(sort_field='web', limit=100)
        template_lists = m.templates.list()
        folderList = m.folders.list("campaign")
    except mailchimp.Error, e:
        return "Ha ocurrido un error con mailchimp<br>" + str(e)
Пример #6
0
def addFolder():
    name = request.form['name']
    folderType = "campaign"
    try:
        m = get_mailchimp_api()
        folder_id = m.folders.add(name, folderType)
    except mailchimp.Error, e:
        return "Ha ocurrido un error al intentar conectar con mailchimp"
Пример #7
0
def delete(campaign_id):
    try:
        m = get_mailchimp_api()
        status = m.campaigns.delete(campaign_id)
    except mailchimp.CampaignDoesNotExistError:
        return json.dumps({"error": u"la campaña no existe"})
    except mailchimp.Error, e:
        return json.dumps({"error": u"Ha ocurrido un error con mailchimp"})
Пример #8
0
def changeFolder():
    folder_id = request.form['area']
    id_camp = request.form['id']
    try:
        m = get_mailchimp_api()
        details = m.campaigns.update(id_camp, 'options',
                                     {'folder_id': folder_id})
    except mailchimp.Error, e:
        return "Ha ocurrido un error con mailchimp", e
Пример #9
0
def details(id):
    try:
        m = get_mailchimp_api()
        details = m.campaigns.list({'campaign_id': id})
        list_id = details['data'][0].get("list_id", 0)
        current_list = m.lists.list(filters={'list_id': list_id})

    except mailchimp.Error, e:
        flash("Ha ocurrido un error: " + str(e), "error")
Пример #10
0
def deleteFolder(area_id):
    area = area_id
    folderType = "campaign"
    try:
        print(area)
        m = get_mailchimp_api()
        folder_id = m.folders.delete(area, folderType)
        print(folder_id)
    except mailchimp.Error, e:
        return "Ha ocurrido un error con mailchimp", e
Пример #11
0
def signUp():
    try:
        _email = request.form['inputEmail']
        chimp = get_mailchimp_api()
        test = chimp.helper.ping()
        subs = chimp.lists.subscribe(app.config['EMAIL_SUBSCRIBER_LIST'],
                                     {'email': _email})
        return json.dumps({'message': 'User created successfully !'})
    except Exception as e:
        return json.dumps({'error': str(e)})
Пример #12
0
def clone(id):
    try:
        m = get_mailchimp_api()
        details = m.campaigns.list({'campaign_id': id})
        content = m.campaigns.content(id)
        lists = m.lists.list(limit=100)
        template_lists = m.templates.list()
        folderList = m.folders.list("campaign")
    except mailchimp.Error, e:
        return index("Ha ocurrido un error con mailchimp" + str(e))
Пример #13
0
def list_details(id, message=None):
    try:
        m = get_mailchimp_api()
        lists = m.lists.list({'list_id': id})
        list = lists['data'][0]
        members = m.lists.members(id)['data']
        segments = m.lists.segments(id)
    except mailchimp.ListDoesNotExistError:
        return index("La lista no existe")
    except mailchimp.Error, e:
        return index("Ha ocurrido un error con mailchimp" + str(e))
Пример #14
0
def sendTest():
    emails = request.form.getlist('email')
    campaignId = request.form['campaignId']
    try:
        m = get_mailchimp_api()
        details = m.campaigns.send_test(campaignId, emails)
        flash("pruebas enviadas correctamente", "success")
    except mailchimp.Error, e:
        flash("Ha ocurrido un error al conectar con mailchimp:\n" + str(e),
              "error")
        return redirect(url_for(".details", id=campaignId))
Пример #15
0
def delete():
    euid = request.form['euid']
    email = request.form['emailDel']
    listId = request.form['listId']
    delete = 'delete' in request.form
    notify = 'notify' in request.form
    try:
        m = get_mailchimp_api()
        status = m.lists.unsubscribe(listId, {
            'email': email,
            'euid': euid
        }, delete, False, notify)
    except mailchimp.Error, e:
        return "Ha ocurrido un error con mailchimp<br />" + str(e)
Пример #16
0
def ajax_buscar_campagnas(pagina=0):
    per_page = 25
    filters = {
        'title': request.form.get('title', ''),
        'exact': False,
        'status': ','.join(request.form.getlist('status')),
        'folder_id': ','.join(request.form.getlist('folder_id')),
        'sendtime_start': request.form.get('sendtime_start', ''),
        'sendtime_end': request.form.get('sendtime_end', ''),
        'folder_id': request.form.get('folder_id', '')
    }
    m = get_mailchimp_api()
    campaignList = m.campaigns.list(filters=filters)
    campaignList = paginate_data(campaignList, pagina, per_page=per_page)

    return json.dumps(campaignList)
Пример #17
0
def add():

    list_id = request.form['id']
    name = request.form['name']
    lastName = request.form['lastName']
    email = request.form['email']
    email = {'email': email}

    merge_vars = {'FNAME': name, 'LNAME': lastName}
    try:
        m = get_mailchimp_api()
        status = m.lists.subscribe(list_id, email, merge_vars, 'html', False,
                                   True, True, False)

        lists = m.lists.list({'list_id': list_id})
        list = lists['data'][0]
        members = m.lists.members(list_id)['data']
    except mailchimp.Error, e:
        return "Ha ocurrido un error con mailchimp<br />" + str(e)
Пример #18
0
def import_csv():
    list_id = request.form['id']
    temp_filename = request.form['emailsFile']
    csv_file = open("/tmp/" + temp_filename, 'r')

    reader = csv.reader(csv_file)
    if 'columnTitle' in request.form:
        reader.next()

    column_headers = []
    column_index = []
    for column in request.form:
        if column.find("headerColumn") == 0:
            column_headers.append(request.form[column])
            column_index.append(column[-1:])

    email_index = int(column_index[column_headers.index("email")])
    name_index = None
    last_name_index = None
    if 'name' in column_headers:
        name_index = int(column_index[column_headers.index("name")])
    if 'lastName' in column_headers:
        last_name_index = int(column_index[column_headers.index("lastName")])
    batch_array = []
    for row in reader:
        email = {'email': row[email_index]}
        merge_vars = {}

        if name_index is not None:
            merge_vars['FNAME'] = row[name_index]
        if last_name_index is not None:
            merge_vars['LNAME'] = row[last_name_index]

        emailRow = {'email': email, 'merge_vars': merge_vars}
        batch_array.append(emailRow)
    try:
        m = get_mailchimp_api()

        status = m.lists.batch_subscribe(list_id, batch_array, False, True,
                                         True)
        message = ""
        if status['add_count'] > 0:
            message += "<div class='alert alert-success'>"
            message += "se han importado <strong>" + str(status['add_count'])
            message += "</strong> emails.<br />"
            message += "</div>"
        if status['update_count'] > 0:
            message += "<div class='alert alert-success'>"
            message += "se han actualizado <strong>"
            message += str(status['update_count']) + "</strong> emails."
            message += "</div>"
        if status['error_count'] > 0:
            message += "<div class='alert alert-danger'>"
            message += "Se encontraron <strong>" + str(status['error_count'])
            message += "</strong> errores al importar."
            message += "<Table class='table'><tr>"
            message += "<th>codigo</th><th>email</th><th>error</th><tr>"
            for error in status["errors"]:
                message += "<tr>"
                message += "<td>" + str(error["code"]) + "</td>"
                message += "<td>" + str(error["email"]["email"]) + "</td>"
                message += "<td>" + str(error["error"]) + "</td>"
                message += "</tr>"
            message += "</Table>"
            message += "</div>"

    except mailchimp.Error, e:
        print "ha ocurrido un error con mailchimp", e
Пример #19
0
def ajax_folder_list():
    return json.dumps(get_mailchimp_api().folders.list("campaign"))
Пример #20
0
def ajax_listar_campagnas(pagina=0):
    per_page = 25
    m = get_mailchimp_api()
    campaignList = m.campaigns.list(start=pagina)
    campaignList = paginate_data(campaignList, pagina)
    return json.dumps(campaignList)