def search_movie(search_criteria): data = json.loads(search_criteria) search = data["search"] myDb = Database.dbConnection() print(myDb) sqlString = "SELECT * FROM titles WHERE primaryTitle LIKE %s" + "%'" + "AND titleType = 'movie'" if "genre:" in search: search = search.replace(" ", "") genre = search.rsplit(":")[-1] sqlString = "SELECT * FROM titles WHERE genres LIKE \'{}\' and titleType = \'movie\' limit 100".format( genre) elif "year:" in search: search = search.replace(" ", "") year = search.rsplit(":")[-1] sqlString = "SELECT * FROM titles WHERE startYear LIKE \'{}\' and titleType = \'movie\' limit 100".format( year) value = search result = Database.selectStatement(myDb, sqlString, value) fetch = result.fetchall() info = {} for row in fetch: info[row[0]] = { "movieID": row[0], "title": row[3], "isAdult": row[4], "startYear": row[5], "runtime": row[7], "genres": row[8] } return json.dumps(info)
def check_user(user_info): data = json.loads(user_info) email = data["email"] userName = data["userName"] myDb = Database.dbConnection() print(myDb) sqlString_Email = "SELECT email FROM users WHERE email = " + "'" + email + "'" sqlString_UserName = "******" + "'" + userName + "'" result1 = Database.selectStatement(myDb, sqlString_Email) result2 = Database.selectStatement(myDb, sqlString_UserName) if (result1.rowcount != 0): return 'email taken' elif (result2.rowcount != 0): return 'username taken' else: return 'clear'
def get_tickets(): myDb = Database.dbConnection() print(myDb) sqlString = "SELECT * FROM tickets" result = Database.selectStatement(myDb, sqlString) fetch = result.fetchall() info = {} for ticket in fetch: info[ticket[0]] = { "ticket_id": ticket[0], "user": ticket[1], "status": ticket[2] } return json.dumps(info)
def get_user(login_info): data = json.loads(login_info) email = data["email"] passwordHash = data["passwordhash"] myDb = Database.dbConnection() print(myDb) sqlString = "SELECT passwordHash, userName FROM users WHERE email = " + "'" + email + "'" result = Database.selectStatement(myDb, sqlString) if (result.rowcount == 1): fetch = result.fetchone() if (fetch[0] == passwordHash): return fetch[1] else: return False
def search_movie(search_criteria): data = json.loads(search_criteria) search = data["search"] myDb = Database.dbConnection() print(myDb) sqlString = "SELECT * FROM titles WHERE primaryTitle LIKE " + "'" + search + "%'" + "AND titleType = 'movie'" result = Database.selectStatement(myDb, sqlString) fetch = result.fetchall() info = {} for row in fetch: info[row[0]] = { "movieID": row[0], "title": row[3], "isAdult": row[4], "startYear": row[5], "runtime": row[7], "genres": row[8] } return json.dumps(info)