Beispiel #1
0
def updates_join():
    if 'dismiss' in flask.request.form:
        flask.session['dismiss'] = True
        return flask.redirect("/candidates")

    email = flask.request.form.get('email', "")
    if email == "" or not re.match("^.*?@.*?\..*?$", email) or "/" in email:
        flask.flash("Please enter your email to subscribe to updates.", 'danger')
        return flask.redirect("/candidates")

    if 'postcode' not in flask.session:
        flask.flash("Enter your postcode before signing up for updates.", 'success')
        return flask.redirect("/")

    postcode = flask.session['postcode']

    lookups.updates_join(app.config, email, postcode)
    flask.session['email'] = email
    flask.flash("Thanks for subscribing to updates! We'll get back to you. Meanwhile, please tell your friends about this on Twitter, Facebook and so on!", 'success')
    return flask.redirect("/candidates")

To unsubscribe, reply to this email and just ask."""

    # Print / send mail
    print("========================================")
    print("To:", subscriber['email'])
    print()
    print(body)
    print("----------------------------------------")

    msg = flask_mail.Message(body=body,
            subject="Easily Tweet to ask MP candidates for their CVs!",
            sender=("Democracy Club CV", "*****@*****.**"),
            recipients=[subscriber['email']]
          )

    if not dry_run:
        with main.app.app_context():
            main.mail.send(msg)
            print("mail sent!")
            # Touch the timestamp so we don't mail them again until time passes
            lookups.updates_join(main.app.config, subscriber['email'], subscriber['postcode'])
            print("touched stamp!")
    else:
        print("Dry run aborted just before send")

    print("========================================")



To unsubscribe, reply to this email and just ask."""

    # Print / send mail
    print("========================================")
    print("To:", subscriber['email'])
    print()
    print(body)
    print("----------------------------------------")

    msg = flask_mail.Message(body=body,
            subject="More MP candidate CVs have arrived!",
            sender=("Democracy Club CVs", "*****@*****.**"),
            recipients=[subscriber['email']]
          )

    if not dry_run:
        with main.app.app_context():
            main.mail.send(msg)
            print("mail sent!")
            # Touch the timestamp so we don't mail them again until time passes
            lookups.updates_join(main.app.config, subscriber['email'], subscriber['postcode'])
            print("touched stamp!")
    else:
        print("Dry run aborted just before send")

    print("========================================")