<commit_before>from flask import Flask, request, render_template
from openpyxl import load_workbook
from openpyxl.utils.datetime import datetime_to_W3CDTF
import cohort
import re
import logging
from pytz import timezone
from datetime import datetime as dt

app = Flask(__name__)

def date_to_string():
    eastern = timezone('US/Eastern')
    date_str = datetime_to_W3CDTF(dt.now(eastern))
    date_str = date_str.replace('T', ' ')
    date_str = date_str.replace('Z', '')
    return date_str

workbook = load_workbook(filename='/home/b7jl/usability/data.xlsx')
worksheet = workbook.active

logging.basicConfig(filename='/home/b7jl/usability/debuglog.log',
                    level=logging.DEBUG,
                    format='%(asctime)s %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S %p')
logging.info('instantiated')

@app.route('/', methods=['GET'])
def submit():
    try:
        logging.info('in the route')
        prototype = request.args.get('prototype')
        element = request.args.get('element')
        logging.debug('type of variable prototype: %s', type(prototype))
        logging.debug('type of variable element: %s', type(element))
        if re.compile(r'[^_a-zA-Z]').search(str(element)):
            return 
        if re.compile(r'[^0-9]').search(str(prototype)):
            return
        else:
            worksheet.append([date_to_string(), cohort.cohort, prototype, element])
            workbook.save('/home/b7jl/usability/data.xlsx')
    except Exception as e:
        logging.warning('threw an exception')
        logging.exception('message')
    return render_template('completed.html')

if __name__ == '__main__':
    app.run(port=8000, host='127.0.0.1', debug=True)<commit_msg>gave up on xlsx and now write straight to txt. 100% coverage<commit_after>from flask import Flask, request, render_template
from openpyxl.utils.datetime import datetime_to_W3CDTF
import cohort
import re
import logging
from pytz import timezone
from datetime import datetime as dt

app = Flask(__name__)

def date_to_string():
    eastern = timezone('US/Eastern')
    date_str = datetime_to_W3CDTF(dt.now(eastern))
    date_str = date_str.replace('T', ' ')
    date_str = date_str.replace('Z', '')
    return date_str


logging.basicConfig(filename='/home/b7jl/usability/debuglog.log',
                    level=logging.DEBUG,
                    format='%(asctime)s %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S %p')
logging.info('instantiated')

@app.route('/', methods=['GET'])
def submit():
    try:
        logging.info('in the route')
        prototype = str(request.args.get('prototype'))
        element = str(request.args.get('element'))
        data = date_to_string() + ',' + cohort.cohort + ',' + prototype + ',' + element + '\n'
        with open('./usability/data.txt', 'a') as f:
            f.write(data)
    except Exception as e:
        logging.warning('threw an exception')
        logging.exception('message')
    return render_template('completed.html')

if __name__ == '__main__':
    app.run(port=8000, host='127.0.0.1', debug=True)
{'fraction_non_alphanumeric': 0.14345718901453958, 'fraction_numerical': 0.010662358642972537, 'mean_word_length': 3.223738062755798, 'pattern_counts': {'":': 0, '<': 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': '5341073', 'n_tokens_mistral': 1014, 'n_tokens_neox': 968, 'n_words': 206}