<commit_before>#!/usr/bin/env python

from flask import Flask

from forms import ApplicationForm
import flask
import logging
import simplejson as json
from integrations import slack

app = Flask(__name__)

app.config.setdefault('WTF_CSRF_ENABLED', False)
LOG_FORMAT = '%(filename)s:%(lineno)s - %(funcName)20s() [%(levelname)s] %(message)s'
logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
logger = logging.getLogger(__name__)

HTTP_HEADER_REQUEST_ID = 'X-Request-ID'


@app.route("/")
def hello():
    d = {'status': 'ok'}
    return flask.jsonify(**d)


@app.route("/webhook/application_form", methods=['POST', 'GET'])
def web_hook_application_form():
    """ Web hook for incoming application forms.
    """
    request_id = flask.request.headers.get(HTTP_HEADER_REQUEST_ID, 'unknown')
    logger.info(u"request_id={} Received form: {}".format(request_id, flask.request.form))
    form = ApplicationForm()
    logger.debug("request_id={} request headers: {}".format(request_id, flask.request.headers))
    d = {
        'status': 'ok',
        'form': flask.request.form
    }
    if form.validate_on_submit():
        slack.post_form_to_webhook(form)
    logger.debug(u"request_id={} d: {}".format(request_id, json.dumps(d)))
    return flask.jsonify(**d)


@app.route("/webhook/eventbrite", methods=['POST', 'GET'])
def web_hook_eventbrite():
    """ Web hook for incoming Eventbrite changes.
    """
    request_id = flask.request.headers.get(HTTP_HEADER_REQUEST_ID, 'unknown')
    # logger.info(u"request_id={} Received Eventbrite notification: {}".format(request_id, flask.request.form))
    request_data = flask.request.get_json()
    logger.debug("request_id={} request headers: {}".format(request_id, flask.request.headers))
    d = {
        'status': 'ok',
        'data': request_data
    }
    logger.debug(u"request_id={} d: {}".format(request_id, json.dumps(d)))
    return flask.jsonify(**d)


@app.route("/webhook/mailchimp", methods=['POST', 'GET'])
def web_hook_mailchimp():
    """ Web hook for incoming MailChimp changes.
    """
    request_id = flask.request.headers.get(HTTP_HEADER_REQUEST_ID, 'unknown')
    request_data = flask.request.get_json()
    # logger.info(u"request_id={} Received MailChimp notification: {}".format(request_id, flask.request.form))
    logger.info("request_id={} headers={} body={}".format(request_id, flask.request.headers, flask.request.data))
    d = {
        'status': 'ok',
        'data': request_data
    }
    logger.debug(u"request_id={} d: {}".format(request_id, json.dumps(d)))
    return flask.jsonify(**d)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)<commit_msg>Add logging for Eventbrite and MailChimp webhooks.<commit_after>#!/usr/bin/env python

from flask import Flask

from forms import ApplicationForm
import flask
import logging
import simplejson as json
from integrations import slack

app = Flask(__name__)

app.config.setdefault('WTF_CSRF_ENABLED', False)
LOG_FORMAT = '%(filename)s:%(lineno)s - %(funcName)20s() [%(levelname)s] %(message)s'
logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
logger = logging.getLogger(__name__)

HTTP_HEADER_REQUEST_ID = 'X-Request-ID'


@app.route("/")
def hello():
    d = {'status': 'ok'}
    return flask.jsonify(**d)


@app.route("/webhook/application_form", methods=['POST', 'GET'])
def web_hook_application_form():
    """ Web hook for incoming application forms.
    """
    request_id = flask.request.headers.get(HTTP_HEADER_REQUEST_ID, 'unknown')
    logger.info(u"request_id={} Received form: {}".format(request_id, flask.request.form))
    form = ApplicationForm()
    logger.debug("request_id={} request headers: {}".format(request_id, flask.request.headers))
    d = {
        'status': 'ok',
        'form': flask.request.form
    }
    if form.validate_on_submit():
        slack.post_form_to_webhook(form)
    logger.debug(u"request_id={} d: {}".format(request_id, json.dumps(d)))
    return flask.jsonify(**d)


@app.route("/webhook/eventbrite", methods=['POST', 'GET'])
def web_hook_eventbrite():
    """ Web hook for incoming Eventbrite changes.
    """
    request_id = flask.request.headers.get(HTTP_HEADER_REQUEST_ID, 'unknown')
    # logger.info(u"request_id={} Received Eventbrite notification: {}".format(request_id, flask.request.form))
    request_data = flask.request.get_json()
    logger.info("request_id={} headers={} body={}".format(request_id, flask.request.headers, json.dumps(request_data)))
    d = {
        'status': 'ok',
        'data': request_data
    }
    logger.debug(u"request_id={} d: {}".format(request_id, json.dumps(d)))
    return flask.jsonify(**d)


@app.route("/webhook/mailchimp", methods=['POST', 'GET'])
def web_hook_mailchimp():
    """ Web hook for incoming MailChimp changes.
    """
    request_id = flask.request.headers.get(HTTP_HEADER_REQUEST_ID, 'unknown')
    request_data = flask.request.get_json()
    # logger.info(u"request_id={} Received MailChimp notification: {}".format(request_id, flask.request.form))
    logger.info("request_id={} headers={} body={}".format(request_id, flask.request.headers, json.dumps(request_data)))
    d = {
        'status': 'ok',
        'data': request_data
    }
    logger.debug(u"request_id={} d: {}".format(request_id, json.dumps(d)))
    return flask.jsonify(**d)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
{'fraction_non_alphanumeric': 0.16564644778334262, 'fraction_numerical': 0.003709886848451122, 'mean_word_length': 4.502040816326531, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1625507', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1807, 'n_words': 337}