<commit_before>from flask import request
import requests, json, datetime
from app import app
from twilio import twiml
import random

@app.route('/get_numbers')
def get_numbers():
    numbers = []
    auth = (app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN'])
    params = {
        "Status" : "completed",
        "StartTime" : str(datetime.date.today())
    }
    r = requests.get("http://api.twilio.com/2010-04-01/Accounts/"+app.config['TWILIO_ACCOUNT_SID']+"/Calls.json", params=params, auth=auth)
    r = r.json()
    for call in r["calls"]:
        if call["from_formatted"] not in numbers:
            numbers.append(call["from_formatted"])
    return json.dumps(numbers)

@app.route('/send_sms/<phone_number>/<message>')
def send_sms(phone_number, message):
	msg_dict = {}
	msg_dict['To'] = phone_number
	msg_dict['From'] = app.config['TWILIO_NUMBER']
	msg_dict['Body'] = message
	twilio_endpoint = "https://api.twilio.com/2010-04-01/Accounts/%s/SMS/Messages.json" % (app.config['TWILIO_ACCOUNT_SID'])
	r = requests.post("%s" %(twilio_endpoint), data = msg_dict, auth=(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN']))
	return json.dumps(r.json())

@app.route('/respond_to_incoming_sms', methods=['GET', 'POST'])
def respond_to_incoming_sms():

    # Get response messags
    headers = {
        "X-Parse-Application-Id" : app.config['X_PARSE_APPLICATION_ID'],
        "X-Parse-REST-API-Key" : app.config['X_PARSE_REST_API_KEY']
    }

    r = requests.get("https://api.parse.com/1/classes/DeathTexts", headers=headers)
    r = r.json()
    r = r['results']

    # Choose random message
    random_message = random.choice(r)
    random_message = random_message['text']

    # Send TwiML response
    resp = twiml.Response()
    resp.sms(random_message)
    return str(resp)

@app.route('/incoming_call', methods=['GET'])
def incoming_call():
    resp = twiml.Response()
    # Play an mp3
    sound = request.args.get("sound")
    resp.play(sound)
    resp.say("Now record your own message.")
    resp.record(maxLength="30", action="/handle_recording")
    return str(resp)
    
@app.route('/handle_recording', methods=['GET', 'POST'])
def handle_recording():
    """Play back the caller's recording."""
 
    recording_url = request.values.get("RecordingUrl", None)
 
    resp = twiml.Response()
    resp.say("That was beautiful.")<commit_msg>Better comments.<commit_after>from flask import request
import requests, json, datetime
from app import app
from twilio import twiml
import random

@app.route('/get_numbers')
def get_numbers():
    numbers = []
    auth = (app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN'])
    params = {
        "Status" : "completed",
        "StartTime" : str(datetime.date.today())
    }
    r = requests.get("http://api.twilio.com/2010-04-01/Accounts/"+app.config['TWILIO_ACCOUNT_SID']+"/Calls.json", params=params, auth=auth)
    r = r.json()
    for call in r["calls"]:
        if call["from_formatted"] not in numbers:
            numbers.append(call["from_formatted"])
    return json.dumps(numbers)

@app.route('/send_sms/<phone_number>/<message>')
def send_sms(phone_number, message):
	msg_dict = {}
	msg_dict['To'] = phone_number
	msg_dict['From'] = app.config['TWILIO_NUMBER']
	msg_dict['Body'] = message
	twilio_endpoint = "https://api.twilio.com/2010-04-01/Accounts/%s/SMS/Messages.json" % (app.config['TWILIO_ACCOUNT_SID'])
	r = requests.post("%s" %(twilio_endpoint), data = msg_dict, auth=(app.config['TWILIO_ACCOUNT_SID'], app.config['TWILIO_AUTH_TOKEN']))
	return json.dumps(r.json())

@app.route('/respond_to_incoming_sms', methods=['GET', 'POST'])
def respond_to_incoming_sms():

    # Setup headers for Parse
    headers = {
        "X-Parse-Application-Id" : app.config['X_PARSE_APPLICATION_ID'],
        "X-Parse-REST-API-Key" : app.config['X_PARSE_REST_API_KEY']
    }

    # Get response messages
    r = requests.get("https://api.parse.com/1/classes/DeathTexts", headers=headers)
    r = r.json()
    r = r['results']

    # Choose random response message
    random_message = random.choice(r)
    random_message = random_message['text']

    # Send random response message as TwiML
    resp = twiml.Response()
    resp.sms(random_message)
    return str(resp)

@app.route('/incoming_call', methods=['GET'])
def incoming_call():
    resp = twiml.Response()
    # Play an mp3
    sound = request.args.get("sound")
    resp.play(sound)
    resp.say("Now record your own message.")
    resp.record(maxLength="30", action="/handle_recording")
    return str(resp)
    
@app.route('/handle_recording', methods=['GET', 'POST'])
def handle_recording():
    """Play back the caller's recording."""
 
    recording_url = request.values.get("RecordingUrl", None)
 
    resp = twiml.Response()
    resp.say("That was beautiful.")
{'fraction_non_alphanumeric': 0.16193828950093186, 'fraction_numerical': 0.008283288465520811, 'mean_word_length': 4.03125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3352078', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1645, 'n_words': 298}