Added flask script
This commit is contained in:
41
server/Flask/main.py
Normal file
41
server/Flask/main.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from flask import Flask, request
|
||||
import mysql.connector
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
# return getData()
|
||||
nodeNumber = request.args.get('nodenumber', default = None)
|
||||
nodeList = request.args.get('nodeList', default = None)
|
||||
# return nodeNumber
|
||||
return nodeList
|
||||
|
||||
|
||||
def getData():
|
||||
try:
|
||||
mydb = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="Dingleberries69!",
|
||||
database="NodeData"
|
||||
)
|
||||
|
||||
cursor = mydb.cursor()
|
||||
query = "SELECT * FROM `Measurement`"
|
||||
cursor.execute(query)
|
||||
result = cursor.fetchall() # Fetch the results
|
||||
|
||||
# Convert the results to a string for display
|
||||
result_str = ', '.join([str(row) for row in result])
|
||||
|
||||
cursor.close()
|
||||
mydb.close()
|
||||
|
||||
return result
|
||||
except mysql.connector.Error as err:
|
||||
print("MySQL Error:", err)
|
||||
return "MySQL Error: " + str(err)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='localhost')
|
Reference in New Issue
Block a user