-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccessMySQLDatabase.py
More file actions
71 lines (62 loc) · 3.07 KB
/
Copy pathaccessMySQLDatabase.py
File metadata and controls
71 lines (62 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pymysql
from flask import Flask, request, jsonify, json
conn = pymysql.connect(host = "sneaker-database-new.c16sew4oi8yj.us-east-1.rds.amazonaws.com", user = "varun", password = "TimAWS98021")
cursor = conn.cursor()
app = Flask(__name__)
@app.route('/check-availability/<product_name>/<color>/<size>')
def check_availability(product_name, color, size):
filteredProducts = []
cursor.execute("SELECT model, color, size, quantity_available FROM sneaker_database.product_inventory WHERE model = " + "\'" + product_name + "\'" + " AND color = " + "\'" + color + "\'" + " AND size = " + str(size) + "AND quantity_available > " + str(0))
for row in cursor :
filteredProducts.append(row)
if((len(filteredProducts) > 0)):
with app.app_context():
return jsonify({"Available" : True}), 200
else:
with app.app_context():
return jsonify({"Available" : False}), 200
#prods = check_availability('Nike Air Force 1', 'White', 6.0)
#print(prods)
@app.route('/check-colors/<product_name>/<size>')
def check_colors(product_name, size):
filteredProducts = []
stringConversion = ""
cursor.execute("SELECT color FROM sneaker_database.product_inventory WHERE model = " + "\'" + product_name + "\'" "AND size = " + str(size) + "AND quantity_available > " + str(0))
for row in cursor :
stringConversion = str(row)
stringConversion = stringConversion[2:len(stringConversion)-3]
filteredProducts.append(stringConversion)
with app.app_context():
return jsonify(filteredProducts), 200
#prods3 = check_colors('Nike Air Force 1', 7.0)
#print(prods3)
@app.route('/check-sizes/<product_name>/<color>')
def check_sizes(product_name, color):
filteredProducts = []
stringConversion = ""
cursor.execute("SELECT size FROM sneaker_database.product_inventory WHERE model = " + "\'" + product_name + "\'" + " AND color = " + "\'" + color + "\'" + "AND quantity_available > " + str(0))
for row in cursor :
stringConversion = str(row)
stringConversion = stringConversion[1:len(stringConversion)-2]
stringValue = stringConversion[stringConversion.find("(")+2:stringConversion.find(")")-1]
filteredProducts.append((float(stringValue)))
with app.app_context():
return jsonify(filteredProducts),200
#prods2 = check_sizes('Nike Air Force 1', 'White')
#print(prods2)
@app.route('/check-products/<size>')
def check_products(size):
filteredProducts = []
stringConversion = ""
cursor.execute("SELECT model, color FROM sneaker_database.product_inventory WHERE size = " + str(size) + " AND quantity_available > " + str(0))
for row in cursor :
stringConversion = str(row)
formattedRow = stringConversion[2:len(stringConversion)-1]
product = formattedRow.partition(",")[0]
color = formattedRow.partition(",")[2]
color = color[2:len(color)-1]
filteredProducts.append(product[0:len(product)-1] + " in " + color)
return filteredProducts
print(check_products(7.5))
if (__name__) == "__main__":
app.run(debug = True)