<commit_before>from bottle import Bottle, request, response, redirect
from email.mime.text import MIMEText
import base64
import httplib2
import oauth2client
from apiclient import discovery
from validate_email_address import validate_email
import logging
import logging.handlers
import os
import requests
import json

config_path = os.path.join(os.getcwd(), 'config.json')

with open(config_path) as config_file:
    config = json.load(config_file)
    config['log_path'] = os.path.join(os.getcwd(), config['log_filename'])

# set up logging
logger = logging.getLogger('contact-me')
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler = logging.handlers.RotatingFileHandler(
            config['log_path'], maxBytes=1000000, backupCount=5)
handler.setFormatter(formatter)
logger.addHandler(handler)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
console.setFormatter(formatter)
logger.addHandler(console)

app = Bottle()

def send_mail(recipient, sender, name, message):
    msg = MIMEText(message)

    msg['Subject'] = '[%s] Contact form submission by %s' % (config['domain'], name)
    msg['From'] = sender
    msg['Reply-To'] = sender
    msg['To'] = recipient

    logger.info(msg.as_string())

    encoded_message = {'raw': base64.urlsafe_b64encode(msg.as_string())}

    credential_path = os.path.join(os.getcwd(), config['credentials_file'])
    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        raise Exception('Invalid credentials - rerun authorize.py')

    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    try:
        sent_message = (service.users().messages().send(userId=config['gmail_username'], body=encoded_message)
                .execute())
        logger.info('Message sent - ID: %s' % sent_message['id'])
        return sent_message
    except errors.HttpError, error:
        logger.error('No message sent - Error: %s' % error)

@app.get('/ip')
def ip():
    response.content_type = 'text/plain'<commit_msg>fix subject line<commit_after>from bottle import Bottle, request, response, redirect
from email.mime.text import MIMEText
import base64
import httplib2
import oauth2client
from apiclient import discovery
from validate_email_address import validate_email
import logging
import logging.handlers
import os
import requests
import json

config_path = os.path.join(os.getcwd(), 'config.json')

with open(config_path) as config_file:
    config = json.load(config_file)
    config['log_path'] = os.path.join(os.getcwd(), config['log_filename'])

# set up logging
logger = logging.getLogger('contact-me')
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler = logging.handlers.RotatingFileHandler(
            config['log_path'], maxBytes=1000000, backupCount=5)
handler.setFormatter(formatter)
logger.addHandler(handler)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
console.setFormatter(formatter)
logger.addHandler(console)

app = Bottle()

def send_mail(recipient, sender, name, message):
    msg = MIMEText(message)

    msg['Subject'] = '[%s] Contact request from %s' % (config['domain'], name)
    msg['From'] = sender
    msg['Reply-To'] = sender
    msg['To'] = recipient

    logger.info(msg.as_string())

    encoded_message = {'raw': base64.urlsafe_b64encode(msg.as_string())}

    credential_path = os.path.join(os.getcwd(), config['credentials_file'])
    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        raise Exception('Invalid credentials - rerun authorize.py')

    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    try:
        sent_message = (service.users().messages().send(userId=config['gmail_username'], body=encoded_message)
                .execute())
        logger.info('Message sent - ID: %s' % sent_message['id'])
        return sent_message
    except errors.HttpError, error:
        logger.error('No message sent - Error: %s' % error)

@app.get('/ip')
def ip():
    response.content_type = 'text/plain'
{'fraction_non_alphanumeric': 0.13271676300578034, 'fraction_numerical': 0.008786127167630059, 'mean_word_length': 4.574742268041237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5050220', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1319, 'n_words': 294}