Untitled
unknown
plain_text
3 years ago
3.8 kB
3
Indexable
from flask import Flask from flask import request from flask import jsonify from flask_cors import CORS import SQL import json app = Flask(__name__) CORS(app) @app.route("/") def hello_world(): return "<p>Hello, World!</p>" @app.route("/user", methods=["get"]) def login(): username = request.args.get('username',"1") password = request.args.get('password',"1") # data = SQL.Server.LOGIN(username,password) data = SQL.Server.LOGIN('atallah','osama') if len(data) == 0: return jsonify(valid="false") else: return jsonify( valid="true", id=data[0][0], first=data[0][1], last=data[0][2], country=data[0][3], city=data[0][4], email=data[0][5], phone=data[0][8], image=data[0][9] ) @app.route("/category",methods=['get']) def getCategory(): _type = request.args.get('type','1') data = [] for d in SQL.Server.getCategory(_type): data.append({ 'id':d[0], 'price': d[1], 'discount': d[2], 'name': d[3], 'image': d[4]}) return jsonify(data) @app.route("/category/product",methods=['get']) def getProduct(): _id = request.args.get('productid','1') data = SQL.Server.getProduct(_id) return jsonify( idcatagory=data[0][1], price=data[0][2], discount=data[0][3], name=data[0][4], image=data[0][5] ) @app.route("/search",methods=['get']) def getSearch(): _query = request.args.get('search','1') data = [] for d in SQL.Server.getSearch(_query): data.append({ 'id': d[0], 'price': d[1], 'discount': d[2], 'name': d[3], 'image': d[4]}) return jsonify(data) @app.route('/random',methods=['get']) def getRandom(): data = [] for d in SQL.Server.getRandom(): data.append({ 'id': d[0], 'price': d[1], 'discount': d[2], 'name': d[3], 'image': d[4]}) return jsonify(data) @app.route("/signup",methods=['get','post']) def signup(): username = request.args.get('username','1') password = request.args.get('password','1') first = request.args.get('first','1') last = request.args.get('last','1') phone = request.args.get('phone','1') country = request.args.get('country','1') email = request.args.get('email','1') pass @app.route('/getorders',methods=['get']) def getOrders(): idbrand = request.args.get('idbrand','1') data = [] for d in SQL.Server.getOrders(idbrand): data.append( { 'pid' : d[0][2], 'pname' : d[2][0][0], 'price' : d[0][5], 'customer' : f'{d[1][0][0]} {d[1][0][1]}' , 'country' : 'Palestine', 'quantity' : '1' } ) return jsonify(data) @app.route('/getproducts',methods=['get']) def getProducts(): idbrand = request.args.get('idbrand','1') _data = SQL.Server.getProductsForBrand(idbrand) data = [] print(len(_data)) for d in _data: data.append( { 'pid' : d[0][0], 'pname' : d[0][5], 'price' : d[0][3], 'category': d[1][0][0], 'discount' : d[0][4], 'image' : d[0][6] } ) return jsonify(data) if __name__ == '__main__': app.run(host="0.0.0.0") # See PyCharm help at https://www.jetbrains.com/help/pycharm/
Editor is loading...