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

from flask import Flask, request
import MySQLdb
import requests

"""
A simple script to test the registration process.
Must be run as root for now.
"""

app = Flask(__name__)


desiredtemp = 0;

@app.route('/register', methods = ['POST'])
def reg_client():
    uuid = request.form['id']
    retstr = "Registered {0}".format(uuid)
    print(retstr)
    return retstr

@app.route('/temp', methods = ['GET'])
def calculate_avg():
    # temp1,temp2,temp3
    r1 = requests.get("http://remote1/temp")
    r2 = requests.get("http://remote2/temp")
    r3 = requests.get("http://remote3/temp")
    temp1 = int(r1.text)
    temp2 = int(r2.text)
    temp3 = int(r3.text)


    avg = temp1 + temp2 + temp3;
    return avg;

@app.route('/status', methods = ['GET'])
def state():
    if (heating):
        return "heating"
    if (cooling):
        return "cooling"
    return "idle"

@app.route('/settemp', method = ['GET'])
def curstate():
    return desiredtemp


@app.route('/settemp', method = ['POST'])
def settemp():
    #r = requests.
    desiredtemp = int(r.text)
    return desiredtemp


@app.route('/temp/<UUID>', method = ['GET'])
def nodetemp():
    r = requests.get("http://remote1/temp/<UUID>")
    temp = int(r.text)
    return temp


@app.route('/state', method = ['GET'])
def state():




@app.route('/state', method = ['POST'])
def setstate():
    payload = {'key1': 'heat', 'key2': 'cool', 'key3': 'off', 'key4': 'default'}
    r = requests.post("http://<gateway>/state", data=payload)
    

# Create a connection object and create a cursor
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="dac_user", passwd="<PASSWORD>", db="tst")
Cursor = Con.cursor()

# Make SQL string and execute it
sql = "SELECT * FROM Users"
Cursor.execute(sql)

# Fetch all results from the cursor into a sequence and close the connection
Results = Cursor.fetchall()
Con.close()







if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80, debug=False)
    

<commit_msg>gateway<commit_after>#!/usr/bin/env python2

from flask import Flask, request
import MySQLdb
import time

"""
A simple script to test the registration process.
Must be run as root for now.
"""

app = Flask(__name__)


desiredtemp = 0;
state = 0;
remote1 = 0;
remote2 = 0;
remote3 = 0;
nodes = {'remote1': 0, 'remote2': 0, 'remote3': 0}


# Create a connection object and create a cursor
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="dac_user", passwd="<PASSWORD>", db="tst")
Cursor = Con.cursor()

# Make SQL string and execute it
sql = "SELECT * FROM Users"
Cursor.execute(sql)

# Fetch all results from the cursor into a sequence and close the connection




#Putting IP addressees to UUIDs
@app.route('/register', methods = ['POST'])
def reg_client():
    uuid = request.form['id']
    retstr = "Registered {0}".format(uuid)
    #while (iter(nodes)):
    #    ip = request.remote_addr;
    for x in range (0, len(nodes)):
        ip = request.remote_addr;
        nodes[x] = ip;
    print(retstr)
    return retstr






@app.route('/temp', methods = ['GET'])
def calculate_avg():
    # temp1,temp2,temp3
    r1 = request.get("http://" + str(nodes[0]) + "/temp")
    r2 = request.get("http://" + str(nodes[1]) + "/temp")
    r3 = request.get("http://" + str(nodes[2]) + "/temp")
    temp1 = int(r1.text)
    temp2 = int(r2.text)
    temp3 = int(r3.text)


    avg = temp1 + temp2 + temp3;

    Cursor.execute("""
    UPDATE projectDB
    SET avg_temp=%s
    WHERE db_index=%s
    """, (avg,0))

    return avg;



#From Database
@app.route('/status', methods = ['GET'])
def state():

    Results = Cursor.fetchall();
    #(avgtemp, settemp, mode, status)
    if (Results(2) == 0):
        return "heating"
    if (Results(2) == 1):
        return "cooling"
    if (Results(2) == 2):
        return "idle"

    return "error"

#From remote node
@app.route('/settemp', method = ['GET'])
def get_temp():
    return desiredtemp

#from Database
@app.route('/settemp', method = ['POST'])
def settemp():
    #r = requests.
    Results = Cursor.fetchall()
    desiredtemp = Results(1);
    return desiredtemp

#from remote node
@app.route('/temp/<UUID>', method = ['GET'])
def nodetemp(uuid):

    r = request.get("http://" + str(nodes[uuid]) + "/temp")
    temp = int(r.text)
    return temp

#To Database
@app.route('/state', method = ['GET'])
def state():

    return state;



#From Database
@app.route('/state', method = ['POST'])
def setstate():
    #r = request.post("http://<gateway>/state", data=payload)



def updateDB():
    print("updated")



var = 1
while var == 1 :  # This constructs an infinite loop
    Results = Cursor.fetchall();
    time.sleep(5);

print "Good bye!"






Con.close()





if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80, debug=False)






{'fraction_non_alphanumeric': 0.1758835758835759, 'fraction_numerical': 0.021621621621621623, 'mean_word_length': 3.303220035778175, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '713811', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1661, 'n_words': 453}