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

from flask import Flask, request, flash, redirect, render_template, jsonify
from flaskext.mysql import MySQL
from flask_wtf import Form
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired
import twilio.twiml
import random
import requests
import json
import omdb
from googleplaces import GooglePlaces, types, lang
from microsofttranslator import Translator
from yahoo_finance import Share
from twilio.rest import TwilioRestClient

gp_api_key = '<KEY>'
google_places = GooglePlaces(gp_api_key)

bing_api_key = '<KEY>'

# Credentials owner: <EMAIL>
# Find these values at https://twilio.com/user/account
twilio_account_sid = "ACab3e465e67051257d227bf49a3c9a58e"
twilio_auth_token = "<PASSWORD>"

admin_phone = "+918095138333"
# admin_phone = "+918095718111"

# Returns a JSON formatted data with a HTTP status code
def dataFormatter(code, message, data):
    resp = jsonify({
            'code': code,
            'message': message,
            'data': data
        })
    resp.status_code = code
    return resp

def get_verify_name(id, s, e):
    verify_url = "http://api.tvmaze.com/shows/" + str(id) + "/episodebynumber?season=" + str(s) + "&number=" + str(e)
    resp = requests.get(verify_url)
    j = json.loads(resp.text)
    name = j['name']
    return name

test_mode = False

app = Flask(__name__)
app.config.from_object('config')

mysql = MySQL()

app.config['MYSQL_DATABASE_USER'] = 'b4dea37336a229'
app.config['MYSQL_DATABASE_PASSWORD'] = '<PASSWORD>'
app.config['MYSQL_DATABASE_DB'] = 'heroku_d5dd20eac082bba'
app.config['MYSQL_DATABASE_HOST'] = 'us-cdbr-iron-east-03.cleardb.net'
mysql.init_app(app)

# Main route

class SMSForm(Form):
    phone_number = StringField('phone_number', validators=[DataRequired()])
    query_string = StringField('query_string', validators=[DataRequired()])
    # password_field = PasswordField('<PASSWORD>', validators=[DataRequired()])

@app.route("/", methods=['GET', 'POST'])
def home_page():
    form = SMSForm()
    if form.validate_on_submit():
        query = str(form.query_string.data)
        number = str(form.phone_number.data)
        # password = str(form.password_field.data)
        # if password == get_verify_name(2, 4, 2):
        print("Sending sms to " + number + " with query \'" + query + "\'.")
        message = process_query(query)
        send_sms_to_number(message, number)
        flash("Sent SMS to " + number + ": \'" + message + "\'.")
        # else:
        #     flash("Invalid secret code, admins are not pleased.")
        return render_template('index.html', form=form, number=number, query=query, showdetails=False)
    return render_template('index.html', form=form, showdetails=True)

class EmergencyForm(Form):
    message_field = StringField('message_field', validators=[DataRequired()])
    location_field = StringField('location_field', validators=[DataRequired()])

@app.route("/emergency/", methods=['GET', 'POST'])
def emergency_page():
    form = EmergencyForm()
    if form.validate_on_submit():
        message = str(form.message_field.data)
        state = str(form.location_field.data)
        print("Broadcasting SMSs to people in state " + str(state))
        # Send SMS to people here...
        conn = mysql.connect()
        try:
            cursor = conn.cursor()
            cursor.execute("SELECT ph_no FROM subscribers WHERE ph_no = %s", (state))
            data = cursor.fetchall()
            for value in data:
                phone_no = value[0]
                print("Sending Broadcast message to " + str(phone_no));
                send_sms_to_number(message, str(phone_no))
            cursor.close()
            conn.close()
        except:
            cursor.close()
            conn.close()
        return render_template('emergency.html', form=form, showdetails=False)
    return render_template('emergency.html', form=form, showdetails=True)

@app.route("/emergency_list/", methods=['GET'])
def emergency_list():
    conn = mysql.connect()
    try:
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM subscribers")
        values = cursor.fetchall()
        data = []
        for value in values:
            d = [value[0], value[1], value[2]]
            data.append(d)
        return dataFormatter(200, "LEL", data)<commit_msg>looks like we need to revise sql queries<commit_after>#!/usr/bin/python

from flask import Flask, request, flash, redirect, render_template, jsonify
from flaskext.mysql import MySQL
from flask_wtf import Form
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired
import twilio.twiml
import random
import requests
import json
import omdb
from googleplaces import GooglePlaces, types, lang
from microsofttranslator import Translator
from yahoo_finance import Share
from twilio.rest import TwilioRestClient

gp_api_key = '<KEY>'
google_places = GooglePlaces(gp_api_key)

bing_api_key = '<KEY>'

# Credentials owner: <EMAIL>
# Find these values at https://twilio.com/user/account
twilio_account_sid = "ACab3e465e67051257d227bf49a3c9a58e"
twilio_auth_token = "<PASSWORD>"

admin_phone = "+918095138333"
# admin_phone = "+918095718111"

# Returns a JSON formatted data with a HTTP status code
def dataFormatter(code, message, data):
    resp = jsonify({
            'code': code,
            'message': message,
            'data': data
        })
    resp.status_code = code
    return resp

def get_verify_name(id, s, e):
    verify_url = "http://api.tvmaze.com/shows/" + str(id) + "/episodebynumber?season=" + str(s) + "&number=" + str(e)
    resp = requests.get(verify_url)
    j = json.loads(resp.text)
    name = j['name']
    return name

test_mode = False

app = Flask(__name__)
app.config.from_object('config')

mysql = MySQL()

app.config['MYSQL_DATABASE_USER'] = 'b4dea37336a229'
app.config['MYSQL_DATABASE_PASSWORD'] = '<PASSWORD>'
app.config['MYSQL_DATABASE_DB'] = 'heroku_d5dd20eac082bba'
app.config['MYSQL_DATABASE_HOST'] = 'us-cdbr-iron-east-03.cleardb.net'
mysql.init_app(app)

# Main route

class SMSForm(Form):
    phone_number = StringField('phone_number', validators=[DataRequired()])
    query_string = StringField('query_string', validators=[DataRequired()])
    # password_field = PasswordField('<PASSWORD>', validators=[DataRequired()])

@app.route("/", methods=['GET', 'POST'])
def home_page():
    form = SMSForm()
    if form.validate_on_submit():
        query = str(form.query_string.data)
        number = str(form.phone_number.data)
        # password = str(form.password_field.data)
        # if password == get_verify_name(2, 4, 2):
        print("Sending sms to " + number + " with query \'" + query + "\'.")
        message = process_query(query)
        send_sms_to_number(message, number)
        flash("Sent SMS to " + number + ": \'" + message + "\'.")
        # else:
        #     flash("Invalid secret code, admins are not pleased.")
        return render_template('index.html', form=form, number=number, query=query, showdetails=False)
    return render_template('index.html', form=form, showdetails=True)

class EmergencyForm(Form):
    message_field = StringField('message_field', validators=[DataRequired()])
    location_field = StringField('location_field', validators=[DataRequired()])

@app.route("/emergency/", methods=['GET', 'POST'])
def emergency_page():
    form = EmergencyForm()
    if form.validate_on_submit():
        message = str(form.message_field.data)
        state = str(form.location_field.data)
        print("Broadcasting SMSs to people in state " + str(state))
        # Send SMS to people here...
        conn = mysql.connect()
        try:
            cursor = conn.cursor()
            cursor.execute("SELECT ph_no FROM subscribers WHERE state = %s", (state))
            data = cursor.fetchall()
            for value in data:
                phone_no = value[0]
                print("Sending Broadcast message to " + str(phone_no));
                send_sms_to_number(message, str(phone_no))
            cursor.close()
            conn.close()
        except:
            cursor.close()
            conn.close()
        return render_template('emergency.html', form=form, showdetails=False)
    return render_template('emergency.html', form=form, showdetails=True)

@app.route("/emergency_list/", methods=['GET'])
def emergency_list():
    conn = mysql.connect()
    try:
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM subscribers")
        values = cursor.fetchall()
        data = []
        for value in values:
            d = [value[0], value[1], value[2]]
            data.append(d)
        return dataFormatter(200, "LEL", data)
{'fraction_non_alphanumeric': 0.12775735294117646, 'fraction_numerical': 0.016659007352941176, 'mean_word_length': 3.3831822759315204, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '4952730', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2688, 'n_words': 620}