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

from __future__ import print_function
from future.standard_library import install_aliases
install_aliases()

from urllib.parse import urlparse, urlencode
from urllib.request import urlopen, Request
from urllib.error import HTTPError

import json
import os
import random

from flask import Flask
from flask import request
from flask import make_response

# Flask app should start in global layout
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])

def webhook():
    req = request.get_json(silent=True, force=True)

    authorization = request.authorization
    print(authorization)

    print("Request:")
    print(json.dumps(req, indent=4))

    res = processRequest(req)

    res = json.dumps(res, indent=4)

    r = make_response(res)

    r.headers['Content-Type'] = 'application/json'
    return r


def processRequest(req):
    if req.get("result").get("action") != "chooseSome":
        return {}

    result = req.get("result")

    data = result.get("parameters")

    res = makeWebhookResult(data)

    return res


def makeWebhookResult(data):
    names = data.get("names")

    if names is None:
        return {}

    k = random.randint(1, max(1,len(names)-1))
    chosen_ones = random.sample(names, k)

    if len(chosen_ones) == 1:
        speech = "I choose " + chosen_ones[0]
    else:
        speech = "I choose " + ", ".join(chosen_ones[:-1]) + " and " + chosen_ones[-1]

    print("Response:")
    print(speech)

    return {
        "speech": speech,
        "displayText": speech,
        # "data": data,
        # "contextOut": [],
        "source": "rose-pick-some-webhook"
    }


if __name__ == '__main__':
    port = int(os.getenv('PORT', 5000))

    print("Starting app on port %d" % port)

    app.run(debug=False, port=port, host='0.0.0.0')
<commit_msg>Add dummy logging for credentials<commit_after>#!/usr/bin/env python

from __future__ import print_function
from future.standard_library import install_aliases
install_aliases()

from urllib.parse import urlparse, urlencode
from urllib.request import urlopen, Request
from urllib.error import HTTPError

import json
import os
import random

from flask import Flask
from flask import request
from flask import make_response

# Flask app should start in global layout
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])

def webhook():
    req = request.get_json(silent=True, force=True)

    username = request.authorization.get("username")
    password = request.authorization.get("password")

    print(username, password)


    print("Request:")
    print(json.dumps(req, indent=4))

    res = processRequest(req)

    res = json.dumps(res, indent=4)

    r = make_response(res)

    r.headers['Content-Type'] = 'application/json'
    return r


def processRequest(req):
    if req.get("result").get("action") != "chooseSome":
        return {}

    result = req.get("result")

    data = result.get("parameters")

    res = makeWebhookResult(data)

    return res


def makeWebhookResult(data):
    names = data.get("names")

    if names is None:
        return {}

    k = random.randint(1, max(1,len(names)-1))
    chosen_ones = random.sample(names, k)

    if len(chosen_ones) == 1:
        speech = "I choose " + chosen_ones[0]
    else:
        speech = "I choose " + ", ".join(chosen_ones[:-1]) + " and " + chosen_ones[-1]

    print("Response:")
    print(speech)

    return {
        "speech": speech,
        "displayText": speech,
        # "data": data,
        # "contextOut": [],
        "source": "rose-pick-some-webhook"
    }


if __name__ == '__main__':
    port = int(os.getenv('PORT', 5000))

    print("Starting app on port %d" % port)

    app.run(debug=False, port=port, host='0.0.0.0')

{'fraction_non_alphanumeric': 0.13480457325179473, 'fraction_numerical': 0.00904014889657006, 'mean_word_length': 3.2653061224489797, 'pattern_counts': {'":': 12, '<': 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': '4051374', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1198, 'n_words': 299}