Untitled
unknown
plain_text
3 years ago
2.8 kB
5
Indexable
from datetime import datetime import os import random import mysql.connector as SQL db = SQL.connect( host='localhost', user='root', password='root', port='3306', database='emarket' ) sql = db.cursor() sss = 'https://p0.pikist.com/photos/591/110/sunset-sea-sky-reflection-water-ocean-evening-landscape-mood.jpg' class Server(): @staticmethod def LOGIN(_username,_password): sql.execute(f"select * from users where username = '{_username}' and password = '{_password}';") data = sql.fetchall() return data @staticmethod def getCategory(_type): sql.execute(f"select id from category where name = '{_type}';") data = sql.fetchall() sql.execute(f"select id,price,discount,name,image from products where idcategory = '{data[0][0]}';") return sql.fetchall() @staticmethod def getProduct(_id): sql.execute(f"select * from products where id = '{_id}';") return sql.fetchall() @staticmethod def getSearch(_query): sql.execute(f"select id from category where name = '{_query}';") data = sql.fetchall() sql.execute(f"select id,price,discount,name,image from products where idcategory = '{data[0][0]}';") return sql.fetchall() @staticmethod def getRandom(): sql.execute('select MAX(id) from products;') data = sql.fetchall() sample = random.sample(range(1,data[0][0]),3) sql.execute(f'select id,price,discount,name,image from products where id = {sample[0]} or id = {sample[1]} or id = {sample[2]};') return sql.fetchall() @staticmethod def signup(username,password,first,last,phone,country,email): pass @staticmethod def getOrders(idbrand): sql.execute(f'select * from orders where idbrand = {idbrand};') _data = sql.fetchall() print(_data) orderData = [] for data in _data: sql.execute(f'select first, last from users where id = {data[1]};') _d = sql.fetchall() sql.execute(f'select name from products where id = {data[2]};') _d2 = sql.fetchall() orderData.append([data ,_d ,_d2]) return orderData @staticmethod def getProductsForBrand(idbrand): sql.execute(f'select * from products where idbrand = {idbrand};') _data = sql.fetchall() productData = [] for d in _data: sql.execute(f'select name from category where id = {d[1]};') productData.append([d , sql.fetchall()]) print("############") print(productData) print(len(productData)) return productData
Editor is loading...