def getItemDetails(itemId: int, db_conn: DBConnection) -> bytes: itemDetails = list( db_conn.execute( f"SELECT TO_CHAR(ITEM_ID), TO_CHAR(USER_ID), P_NAME, TO_CHAR(CATEGORY_ID), PICTURE, TO_CHAR(S_PRICE), TO_CHAR(S_DATE), TO_CHAR(END_DATE), DESCRIPTION FROM ITEMS WHERE ITEM_ID = {itemId}" )[0]) itemCategory = db_conn.execute( f"SELECT CATEGORY_NAME FROM CATEGORIES WHERE CATEGORY_ID = {itemDetails[3]}" )[0][0] itemTags = db_conn.execute( f"SELECT CHARACTERISTIC_NAME, CHARACTERISTIC_VALUE FROM TAGS WHERE ITEM_ID = {itemId}" ) itemTags = "!".join(f"{tag_name}~{tag_val}" for tag_name, tag_val in itemTags) itemSeller, itemTlf, itemEmail, itemLocation = db_conn.execute( f"SELECT USERNAME, TELEPHONE, EMAIL, COUNTRY||', '||CITY FROM SITE_USERS WHERE USER_ID = {itemDetails[1]}" )[0] itemDetails.append(itemCategory) itemDetails.append(itemTags) itemDetails.append(itemSeller) itemDetails.append(itemTlf) itemDetails.append(itemEmail) itemDetails.append(itemLocation) return "???".join(itemDetails).encode()
def login(username: str, password: str, db_conn: DBConnection, activeUsers: dict) -> bytes: """ Checks the user id and SHA256 of the pw against the DB. Adds the tuple (user id, SHA256(user id + pw + str(time.asctime()))) to the active users dict. Returns the hash computed above. """ result = db_conn.execute( f"SELECT COUNT(*) FROM SITE_USERS WHERE USERNAME LIKE '{username}' AND PASSWORD LIKE '{unicodeHash(password)}'" ) #AND PASSWORD LIKE '{str(passwordHash)}'" ) print("Result: ", result) print("PasswordHash: ", unicodeHash(password)) print( "Select... ", db_conn.execute( "SELECT PASSWORD FROM SITE_USERS WHERE USERNAME LIKE 'username'")) if result == [(0, )]: return "LOGINFAIL".encode() else: userHash = unicodeHash(username + password + str(time.asctime())) activeUsers[userHash] = username return ("LOGINSUCCESS?" + userHash).encode()
def advancedSearchPage(page: str, tags: str, db_conn: DBConnection) -> bytes: tags = [constraint.split("~") for constraint in tags.split("?")] tags = {name: value for name, value in tags} query = f"SELECT {_search_template} FROM ITEMS" # CATEGORY # NAME # FABRICATIONLOCATION # FABRICATIONYEAR # CONDITION # MATERIAL # COLOR # OTHER for tag_name, tag_val in tags.items(): if query == f"SELECT {_search_template} FROM ITEMS": query += " WHERE " else: query += " AND " query += _constraint_types[tag_name](tag_val) db_conn.execute(query) pages = db_conn.getResultsInPagesOf(9) pages = [page for page in pages if page] print("Pages:", pages) try: requestedPage = pages[int(page) - 1] except IndexError: return b'0!0!0!0!' print("RequestedPage", requestedPage) print('\n'.join(' | '.join(row) for row in requestedPage)) curPage = int(page) maxPage = len(pages) hasPrevPage = 1 if curPage > 1 else 0 hasNextPage = 1 if curPage < maxPage else 0 result = '!'.join( (str(hasPrevPage), str(hasNextPage), str(curPage), str(maxPage), '#'.join('???'.join(row) for row in requestedPage))) print("RESULT:", result) return result.encode()
def getAuctionsAsPDF(db_handler: DBConnection) -> bytes: result = db_handler.execute( f"SELECT TO_CHAR(I.ITEM_ID), I.P_NAME, TO_CHAR(I.S_PRICE), TO_CHAR(I.S_DATE), TO_CHAR(I.END_DATE), C.CATEGORY_NAME FROM ITEMS I JOIN CATEGORIES C ON I.CATEGORY_ID = C.CATEGORY_ID WHERE SYSDATE < I.END_DATE" ) print(result) results = "" nrobiecte = 0 for ind in range(len(result)): for ind2 in range(6): if (ind2 % 6 == 0): results += ' Item id: ' + result[ind][ind2] + 'endl' nrobiecte += 1 if (ind2 % 6 == 1): results += ' Name: ' + result[ind][ind2] + 'endl' nrobiecte += 1 if (ind2 % 6 == 2): results += ' Price: ' + result[ind][ind2] + 'endl' nrobiecte += 1 if (ind2 % 6 == 3): results += ' Start date: ' + result[ind][ind2] + 'endl' nrobiecte += 1 if (ind2 % 6 == 4): results += ' End date: ' + result[ind][ind2] + 'endl' nrobiecte += 1 if (ind2 % 6 == 5): results += ' Category: ' + result[ind][ind2] + 'endl' nrobiecte += 1 # if(ind2 % 6 == 6): # results += ' Characteristic name: ' + result[ind][ind2] # if(ind2 % 6 == 7): # results += 'Characteristic value: ' + result[ind][ind2] curItemId = result[ind][0] tags = db_handler.execute( f"SELECT CHARACTERISTIC_NAME, CHARACTERISTIC_VALUE FROM TAGS where ITEM_ID = {curItemId}" ) for index in range(len(tags)): results += tags[index][0] + ' : ' + tags[index][1] + 'endl' nrobiecte += 1 print(results) print('NR OBIECTE: ', nrobiecte) pdf = FPDF() pdf.add_page() pdf.set_font('Arial', 'B', 10) for index in range(nrobiecte): curString = results.split('endl')[index] pdf.cell(0, 10, curString, 0, 2) pdf.output('auctionsPDF.pdf', 'F') return open('auctionsPDF.pdf', 'rb').read()
def deleteAuction(receivedAuctionId, db_handler: DBConnection): #db_handler._DEBUG_dbCursor.execute(f"CREATE OR REPLACE VIEW COPY_ITEMS as select * from ITEMS;") #db_handler._DEBUG_dbCursor.execute(f"CREATE OR REPLACE TRIGGER DELETE_ITEM INSTEAD OF delete ON COPY_ITEMS BEGIN delete from TAGS where item_id =:OLD.item_id; delete from ITEMS where item_id =:OLD.item_id;END;") #result = db_handler._DEBUG_dbCursor.execute(f"delete from COPY_ITEMS where item_id='{receivedAuctionId}'") #db_handler.execute('commit') result = db_handler._DEBUG_dbCursor.execute( f"delete from copy_items where item_id='{receivedAuctionId}'") db_handler.execute('commit') print(result) if result != []: message = "DELETE SUCCCES" else: message = "FAIL" return message.encode()
def getAuction (receivedUsername, db_handler: DBConnection)->bytes: user_id = db_handler.execute (f"select user_id from SITE_USERS where username like '{receivedUsername}'")[0][0] response_nr = db_handler.execute (f"select count(item_id) from items where user_id like '{user_id}' ")[0][0] #[1][0] response = db_handler.execute (f"select item_id from items where user_id like '{user_id}' ") #print(str(response[0][0])) #return str(response[0][0]).encode() string1 = str(response_nr) + "?" for i in range(0,response_nr): raspuns = response[i][0] string = str(raspuns) + "?" string1 = string1 + string #print(string1) return string1.encode()
def getProfileInfo(username: str, db_conn: DBConnection) -> bytes: result = list(db_conn.execute(f"SELECT * FROM SITE_USERS WHERE USERNAME LIKE '{username}'")[0][1:]) del result[4] #firstName, lastName, email, _, country, city, tel, picLink = result return "???".join(result).encode()
def simpleSearchPage(toBeSearched: str, page: str, db_handler: DBConnection) -> bytes: allresults = db_handler.execute( f"SELECT TO_CHAR(ITEM_ID), TO_CHAR(USER_ID), P_NAME, TO_CHAR(CATEGORY_ID), PICTURE, TO_CHAR(S_PRICE), TO_CHAR(S_DATE), TO_CHAR(END_DATE), DESCRIPTION FROM ITEMS WHERE LOWER(P_NAME) LIKE '%{toBeSearched}%'") print("all results:", len(allresults)) resultPages = db_handler.getResultsInPagesOf(9) print("Result pages: ", resultPages) # firstName, lastName, email, _, country, city, tel, picLink = result pages = [page for page in resultPages if page] print("Pages:", pages) try: requestedPage = pages[int(page) - 1] except IndexError: return b'0!0!0!0!' print("RequestedPage", requestedPage) print('\n'.join(' | '.join(row) for row in requestedPage)) curPage = int(page) maxPage = len(pages) hasPrevPage = 1 if curPage > 1 else 0 hasNextPage = 1 if curPage < maxPage else 0 result = '!'.join(( str(hasPrevPage), str(hasNextPage), str(curPage), str(maxPage), '#'.join( '???'.join(row) for row in requestedPage ) )) print("RESULT:", result) return result.encode()
def getItemFields (receivedAuctionId, db_handler: DBConnection): result = db_handler.execute(f"select p_name,s_price,s_date,end_date,description from ITEMS where item_id='{receivedAuctionId}'") nume = result[0][0] s_price = result[0][1] s_date = result[0][2] end_date = result[0][3] description = result[0][4] message = nume + "?" + str(s_price) + "?" + str(s_date) + "?" + str(end_date) + "?" + description return message.encode()
def mostRecent(db_conn: DBConnection): result = db_conn.execute( f"SELECT PICTURE, P_NAME, TO_CHAR(S_PRICE), TO_CHAR(END_DATE) FROM ITEMS ORDER BY END_DATE ASC" )[:9] print("Result: ", result) for ind in range(len(result)): print(len(result), ind) print(result[ind]) result[ind] = '?'.join(result[ind]) print(result[ind]) lastresult = "#".join(result) print("REZULTAT FINAL:", lastresult) return lastresult.encode()
def getAuctionsAsJson(db_handler: DBConnection) -> bytes: result = db_handler.execute( f"SELECT ITEM_ID, P_NAME, S_PRICE, DESCRIPTION, TO_CHAR(END_DATE) FROM ITEMS WHERE SYSDATE < END_DATE" ) auctions = dict() for ind in range(len(result)): auctions[str(ind)] = { 'Name': result[ind][1], 'Price': result[ind][2], 'Description': result[ind][3], 'End date': result[ind][4] } jsn = json.dumps(auctions) print(auctions) print() print(jsn) return jsn.encode()
def getAuctionsAsXML(db_handler: DBConnection) -> bytes: result = db_handler.execute( f"SELECT TO_CHAR(ITEM_ID), P_NAME, TO_CHAR(S_PRICE), DESCRIPTION, TO_CHAR(END_DATE) FROM ITEMS WHERE SYSDATE < END_DATE" ) auctions = ET.Element("auctions") for ind in range(len(result)): item = ET.SubElement(auctions, "item") for ind2 in range(5): if (ind2 % 5 == 0): ET.SubElement(item, "item_id").text = result[ind][ind2] if (ind2 % 5 == 1): ET.SubElement(item, "item_name").text = result[ind][ind2] if (ind2 % 5 == 2): ET.SubElement(item, "item_price").text = result[ind][ind2] if (ind2 % 5 == 3): ET.SubElement(item, "item_description").text = result[ind][ind2] if (ind2 % 5 == 4): ET.SubElement(item, "end_date").text = result[ind][ind2] tree = ET.ElementTree(auctions) tree.write('auctions.xml') return open('auctions.xml', 'rb').read()
class Server(BaseHTTPRequestHandler): db_conn = DBConnection.connect("WEB", "WEB", "localhost") activeUsers = dict() content_types = { '.css': 'text/css', '.gif': 'image/gif', '.htm': 'text/html', '.html': 'text/html', '.jpeg': 'image/jpeg', '.jpg': 'image/jpg', '.js': 'text/javascript', '.png': 'image/png', '.text': 'text/plain', '.txt': 'text/plain' } frontend_files = set( itertools.chain.from_iterable( files for _, _, files in os.walk('..\\Frontend'))) def do_GET(self): self.send_response(200) content_type, content_body = self.dispatch() self.send_header('Content-type', content_type) self.end_headers() try: self.wfile.write(content_body) except Exception as e: print( "==========================================================================\n" + str(e) + f'\nRequest: \n' f' type : <{self.command}> \n' f' path : <{self.path}> \n' f' requestline: <{self.requestline}> \n' f' requestline.split(" ")[0]: <{self.requestline.split(" ")[0]}> \n' f' requestline.split(" ")[1]: <{self.requestline.split(" ")[1]}> \n' f' requestline.split(" ")[2]: <{self.requestline.split(" ")[2]}> \n' "========================================================================\n" ) def do_POST(self): print('\n\n===\n\nyey\n\n===\n\n') def dispatch(self) -> Tuple[str, bytes]: print( f'Request: \n' f' type : <{self.command}> \n' f' path : <{self.path}> \n' f' requestline: <{self.requestline}> \n' f' requestline.split(" ")[0]: <{self.requestline.split(" ")[0]}> \n' f' requestline.split(" ")[1]: <{self.requestline.split(" ")[1]}> \n' f' requestline.split(" ")[2]: <{self.requestline.split(" ")[2]}> \n' ) content_type = "text/html" content_body = "Error in the dispatch function".encode() requestContents = self.requestline.split()[1] if requestContents == '/' or requestContents == self.path and requestContents.split( '/')[-1] in self.frontend_files: print('PATH ', self.path, '\nCONT ', requestContents) if self.path == '/' or self.path == '/favicon.ico': self.path = '/index.html' content_type = self.__class__.content_types[os.path.splitext( self.path)[1]] content_body = open('../Frontend' + self.path, 'rb').read() if requestContents.startswith("/SEARCH"): toBeSearched = requestContents.split("?")[1] content_body = testSearch(toBeSearched, self.__class__.db_conn) if requestContents.startswith("/LOGIN"): receivedUsername = requestContents.split("?")[1] receivedPassword = requestContents.split("?")[2] content_body = login(receivedUsername, receivedPassword, self.__class__.db_conn, self.__class__.activeUsers) print(content_body) if requestContents.startswith("/LOGOUT"): userHash = requestContents.split("?")[1].replace("%20", " ") content_body = logout(userHash, self.__class__.activeUsers) if requestContents.startswith("/GETPROFILEINFO"): userHash = requestContents.split("?")[1].replace("%20", " ") content_body = getProfileInfo(self.__class__.activeUsers[userHash], self.__class__.db_conn) if requestContents.startswith("/REGISTER"): print(requestContents) fname = requestContents.split("?")[1] lname = requestContents.split("?")[2] username = requestContents.split("?")[3] password = requestContents.split("?")[4] country = requestContents.split("?")[5] city = requestContents.split("?")[6] tel = requestContents.split("?")[7] email = requestContents.split("?")[8] link = requestContents.split("?")[9] content_body = register(fname, lname, username, password, country, city, tel, email, link, self.__class__.db_conn) if requestContents.startswith("/CHANGE"): newFirstName = requestContents.split("?")[1] newLastName = requestContents.split("?")[2] newPass = requestContents.split("?")[3] newCity = requestContents.split("?")[4] newTel = requestContents.split("?")[5] newEmail = requestContents.split("?")[6] newLink = requestContents.split("?")[7] userHash = requestContents.split("?")[8].replace("%20", " ") if userHash in self.activeUsers: username = self.activeUsers[userHash] content_body = changeInfo(newFirstName, newLastName, newPass, newCity, newTel, newEmail, newLink, self.__class__.db_conn, username) else: content_body = "You are not logged in.".encode() if requestContents.startswith("/ISUSERLOGGEDIN"): print( "requestContents.split('?')[1].replace('%20', ' ') in self.activeUsers", requestContents.split('?')[1].replace('%20', ' ') in self.activeUsers) if requestContents.split('?')[1].replace('%20', ' ') in self.activeUsers: content_body = "USERLOGGEDINSUCCESS".encode() else: # except Exception as e: content_body = "USERLOGGEDINFAIL".encode() if requestContents.startswith("/NEWAUCTION"): #TODO: verify if user is logged in # print (requestContents) receivedName = requestContents.split("???")[1].replace("%20", " ") receivedCategory = requestContents.split("???")[2].replace( "%20", " ") receivedPicture = requestContents.split("???")[3].replace( "%20", " ") receivedPrice = requestContents.split("???")[4].replace("%20", " ") receivedStartD = requestContents.split("???")[5].replace( "%20", " ") receivedEndD = requestContents.split("???")[6].replace("%20", " ") receivedDesc = requestContents.split("???")[7].replace("%20", " ") receivedFabCountry = requestContents.split("???")[8].replace( "%20", " ") receivedFabYear = requestContents.split("???")[9].replace( "%20", " ") receivedCondition = requestContents.split("???")[10].replace( "%20", " ") receivedMaterial = requestContents.split("???")[11].replace( "%20", " ") receivedColor = requestContents.split("???")[12].replace( "%20", " ") receivedSpecialCarac = requestContents.split("???")[13].replace( "%20", " ") receivedUsernameHash = requestContents.split("???")[14].replace( "%20", " ") print("UsernameHash", receivedUsernameHash) receivedUsername = self.__class__.activeUsers[receivedUsernameHash] content_body = newAuction( receivedUsername, receivedName, receivedCategory, receivedPicture, receivedPrice, receivedStartD, receivedEndD, receivedDesc, receivedFabCountry, receivedFabYear, receivedCondition, receivedMaterial, receivedColor, receivedSpecialCarac, self.__class__.db_conn) # print(requestContents,requestContents.startswith("/NEWAUCTION")) if requestContents.startswith("/GETSIMPLESEARCHRESULTSPAGE"): page, itemName = requestContents.replace("%20", " ").split("?")[1:] print("to be searched: ", itemName) print("page:", page) content_body = simpleSearchPage(itemName.lower(), page, self.__class__.db_conn) if requestContents.startswith("/RECENT"): content_body = mostRecent(self.__class__.db_conn) if requestContents.startswith("/GETADVANCEDSEARCHRESULTSPAGE"): page, tags = requestContents.replace("%20", " ").split("!")[1:] content_body = advancedSearchPage(page, tags, self.db_conn) if requestContents.startswith("/GETITEMDETAILS"): itemId = int(requestContents.split("?")[-1]) content_body = getItemDetails(itemId, self.db_conn) if requestContents.startswith("/USERAUCTIONS"): receivedUsernameHash = requestContents.split("?")[1].replace( "%20", " ") receivedUsername = self.__class__.activeUsers[receivedUsernameHash] content_body = getAuction(receivedUsername, self.__class__.db_conn) if requestContents.startswith("/DELETE"): receivedAuctionId = requestContents.split("?")[1] print(receivedAuctionId) content_body = deleteAuction(receivedAuctionId, self.__class__.db_conn) print("out of function") if requestContents.startswith("/GETJSONEXPORT"): userHash = requestContents.replace('%20', ' ').split('?')[1] content_body = getAuctionsAsJson(self.db_conn) if requestContents.startswith("/GETPDFEXPORT"): userHash = requestContents.replace('%20', ' ').split('?')[1] content_body = getAuctionsAsPDF(self.db_conn) content_type = 'application/pdf' if requestContents.startswith("/GETXMLEXPORT"): userHash = requestContents.replace('%20', ' ').split('?')[1] content_body = getAuctionsAsXML(self.db_conn) content_type = 'text/xml' if requestContents.startswith("/NEWBID"): offer = requestContents.replace('%20', ' ').split('?')[1] itemId = requestContents.replace('%20', ' ').split('?')[2] userHash = requestContents.replace('%20', ' ').split('?')[3] content_body = newBid(itemId, offer, self.db_conn) if requestContents.startswith("/EDIT"): receivedName = requestContents.split("???")[1].replace("%20", " ") receivedCategory = requestContents.split("???")[2].replace( "%20", " ") receivedPicture = requestContents.split("???")[3].replace( "%20", " ") receivedPrice = requestContents.split("???")[4].replace("%20", " ") receivedStartD = requestContents.split("???")[5].replace( "%20", " ") receivedEndD = requestContents.split("???")[6].replace("%20", " ") receivedDesc = requestContents.split("???")[7].replace("%20", " ") receivedFabCountry = requestContents.split("???")[8].replace( "%20", " ") receivedFabYear = requestContents.split("???")[9].replace( "%20", " ") receivedCondition = requestContents.split("???")[10].replace( "%20", " ") receivedMaterial = requestContents.split("???")[11].replace( "%20", " ") receivedColor = requestContents.split("???")[12].replace( "%20", " ") receivedSpecialCarac = requestContents.split("???")[13].replace( "%20", " ") receivedItemId = requestContents.split("???")[14].replace( "%20", " ") #print ("ItemId", receivedItemId) content_body = editAuction( receivedItemId, receivedName, receivedCategory, receivedPicture, receivedPrice, receivedStartD, receivedEndD, receivedDesc, receivedFabCountry, receivedFabYear, receivedCondition, receivedMaterial, receivedColor, receivedSpecialCarac, self.__class__.db_conn) if requestContents.startswith("/GETITEMFIELDS"): receivedAuctionId = requestContents.split("???")[1] #print("LICITATIA ACTIVA" + receivedAuctionId) content_body = getItemFields(receivedAuctionId, self.__class__.db_conn) return content_type, content_body
def changeInfo(newFirstName, newLastName, newPass, newCity, newTel, newEmail, newLink, db_conn: DBConnection, username): ok=1 if newFirstName != "": result1 = db_conn.execute(f"UPDATE SITE_USERS SET FIRST_NAME='{newFirstName}' WHERE username LIKE '{username}'") if result1 == []: ok = 0 else: db_conn.execute("Commit") if newLastName != "": result2 = db_conn.execute(f"UPDATE SITE_USERS SET LAST_NAME='{newLastName}' WHERE username LIKE '{username}'") if result2 == []: ok=0 else: db_conn.execute("Commit") hashPass = unicodeHash(newPass) if newPass != "": result = db_conn.execute(f"UPDATE SITE_USERS SET PASSWORD='******' WHERE username LIKE '{username}'") if result == []: ok=0 else: db_conn.execute("Commit") if newCity != "": result3 = db_conn.execute(f"UPDATE SITE_USERS SET CITY='{newCity}' WHERE username LIKE '{username}'") if result3 == []: ok=0 else: db_conn.execute("Commit") if newTel != "": result4 = db_conn.execute(f"UPDATE SITE_USERS SET TELEPHONE ='{newTel}' WHERE username LIKE '{username}'") if result4 == []: ok=0 else: db_conn.execute("Commit") if newEmail != "": result5 = db_conn.execute(f"UPDATE SITE_USERS SET EMAIL='{newEmail}' WHERE username LIKE '{username}'") if result5 == []: ok=0 else: db_conn.execute("Commit") if newLink != "": result6 = db_conn.execute(f"UPDATE SITE_USERS SET LINK_PIC='{newLink}' WHERE username LIKE '{username}'") if result6 == []: ok=0 else: db_conn.execute("Commit") if ok == 1: message = "Update successful." else: message = "Update failed." return message.encode()
def newAuction(receivedUsername, receivedName, receivedCategory, receivedPicture, receivedPrice, receivedStartD, receivedEndD, receivedDesc, receivedFabCountry, receivedFabYear, receivedCondition, receivedMaterial, receivedColor, receivedSpecialCarac, db_handler: DBConnection): # print(receivedUsername) receivedContent = receivedName.split("::::")[1] if receivedContent == "": message = 'COMPULSORY FIELD IS EMPTY: ITEM NAME' return message.encode() receivedContent1 = receivedCategory.split("::::")[1] if receivedContent1 == "": message = 'COMPULSORY FIELD IS EMPTY: CATEGORY' return message.encode() receivedContent2 = receivedPicture.split("::::")[1] if receivedContent2 == "": message = 'COMPULSORY FIELD IS EMPTY: LINK TO A PICTURE' return message.encode() receivedContent3 = receivedPrice.split("::::")[1] if receivedContent3 == "": message = 'COMPULSORY FIELD IS EMPTY: START PRICE' return message.encode() receivedContent4 = receivedStartD.split("::::")[1] if receivedContent4 == "": message = 'COMPULSORY FIELD IS EMPTY: START DATE' return message.encode() receivedContent5 = receivedEndD.split("::::")[1] if receivedContent5 == "": message = 'COMPULSORY FIELD IS EMPTY: END DATE' return message.encode() if receivedContent4 > receivedContent5: message = 'START DATE MUST BE LOWER THAN END DATE' return message.encode() receivedContent6 = receivedDesc.split("::::")[1] receivedContent1 = receivedContent1.split("%20")[0] receivedContent1 = receivedContent1.replace("and", "&") print("recContent", receivedContent1) id_category = db_handler.execute( f"select category_id from categories where INSTR(category_name,'{receivedContent1}') > 0 " ) print("idCategory", id_category) category_id = id_category[0][0] id_item = db_handler.execute(f"select max(item_id) from items") id = id_item[0][0] + 1 us_id = db_handler.execute( f"select user_id from SITE_USERS where username like '{receivedUsername}'" ) username_id = us_id[0][0] if receivedContent6 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into ITEMS values('{id}','{username_id}','{receivedContent}','{category_id}','{receivedContent2}','{receivedContent3}',TO_TIMESTAMP('{receivedContent4}','yyyy-mm-dd'), TO_TIMESTAMP('{receivedContent5}','yyyy-mm-dd'),'{receivedContent6}')" ) db_handler.execute('commit') else: result = db_handler._DEBUG_dbCursor.execute( f"insert into ITEMS values('{id}','{username_id}','{receivedContent}','{category_id}','{receivedContent2}','{receivedContent3}',TO_TIMESTAMP('{receivedContent4}','yyyy-mm-dd'), TO_TIMESTAMP('{receivedContent5}','yyyy-mm-dd'),null)" ) db_handler.execute('commit') id_tag = db_handler.execute(f"select max(id) from tags") tag_id = id_tag[0][0] + 1 receivedCategory = receivedFabCountry.split("::::")[0] receivedContent7 = receivedFabCountry.split("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into TAGS values('{tag_id}','{id}','{receivedCategory}','{receivedContent7}')" ) db_handler.execute('commit') id_tag = db_handler.execute(f"select max(id) from tags") tag_id = id_tag[0][0] + 1 receivedCategory = receivedFabYear.split("::::")[0] receivedContent7 = receivedFabYear.split("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into TAGS values('{tag_id}','{id}','{receivedCategory}','{receivedContent7}')" ) db_handler.execute('commit') id_tag = db_handler.execute(f"select max(id) from tags") tag_id = id_tag[0][0] + 1 receivedCategory = receivedCondition.split("::::")[0] receivedContent7 = receivedCondition.split("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into TAGS values('{tag_id}','{id}','{receivedCategory}','{receivedContent7}')" ) db_handler.execute('commit') id_tag = db_handler.execute(f"select max(id) from tags") tag_id = id_tag[0][0] + 1 receivedCategory = receivedMaterial.split("::::")[0] receivedContent7 = receivedMaterial.split("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into TAGS values('{tag_id}','{id}','{receivedCategory}','{receivedContent7}')" ) db_handler.execute('commit') id_tag = db_handler.execute(f"select max(id) from tags") tag_id = id_tag[0][0] + 1 receivedCategory = receivedColor.split("::::")[0] receivedContent7 = receivedColor.split("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into TAGS values('{tag_id}','{id}','{receivedCategory}','{receivedContent7}')" ) db_handler.execute('commit') id_tag = db_handler.execute(f"select max(id) from tags") tag_id = id_tag[0][0] + 1 receivedCategory = receivedSpecialCarac.split("::::")[0] receivedContent7 = receivedSpecialCarac.split("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute( f"insert into TAGS values('{tag_id}','{id}','{receivedCategory}','{receivedContent7}')" ) db_handler.execute('commit') if result != []: message = "SUCCCES" else: message = "FAIL" return message.encode()
def editAuction(receivedItemId, receivedName, receivedCategory, receivedPicture, receivedPrice, receivedStartD, receivedEndD, receivedDesc, receivedFabCountry, receivedFabYear, receivedCondition, receivedMaterial, receivedColor, receivedSpecialCarac, db_handler: DBConnection): receivedContent = receivedName.split ("::::")[1] if receivedContent != "": result = db_handler._DEBUG_dbCursor.execute ( f"update ITEMS set p_name='{receivedContent}' where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedContent1 = receivedCategory.split ("::::")[1] if receivedContent1 != "": receivedContent1 = receivedContent1.split ("%20")[0] category_id = db_handler.execute (f"select category_id from categories where INSTR(category_name,'{receivedContent1}') > 0")[0][0] result = db_handler._DEBUG_dbCursor.execute (f"update ITEMS set category_id ='{category_id}' where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedContent2 = receivedPicture.split ("::::")[1] if receivedContent2 != "": result = db_handler.execute(f"update ITEMS set picture ='{receivedContent2}' where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedContent3 = receivedPrice.split ("::::")[1] if receivedContent3 != "": result = db_handler._DEBUG_dbCursor.execute (f"update ITEMS set s_price ='{receivedContent3}' where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedContent4 = receivedStartD.split ("::::")[1] receivedContent5 = receivedEndD.split ("::::")[1] if receivedContent4 > receivedContent5: message = 'START DATE MUST BE LOWER THAN END DATE' return message.encode ( ) if receivedContent4 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update ITEMS set s_price =TO_TIMESTAMP('{receivedContent4}','yyyy-mm-dd') where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() if receivedContent5 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update ITEMS set end_price =TO_TIMESTAMP('{receivedContent5}','yyyy-mm-dd') where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedContent6 = receivedDesc.split ("::::")[1] if receivedContent6 != "": result = db_handler._DEBUG_dbCursor.execute (f"update ITEMS set description = '{receivedContent6}' where item_id='{receivedItemId}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedCategory = receivedFabCountry.split ("::::")[0] receivedContent7 = receivedFabCountry.split ("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update TAGS set characteristic_value ='{receivedContent7}'" f"where item_id='{receivedItemId}' and characteristic_name like'{receivedCategory}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode ( ) receivedCategory = receivedFabYear.split ("::::")[0] receivedContent7 = receivedFabYear.split ("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update TAGS set characteristic_value ='{receivedContent7}'" f"where item_id='{receivedItemId}' and characteristic_name like'{receivedCategory}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode() receivedCategory = receivedCondition.split ("::::")[0] receivedContent7 = receivedCondition.split ("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update TAGS set characteristic_value ='{receivedContent7}'" f"where item_id='{receivedItemId}' and characteristic_name like'{receivedCategory}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode ( ) receivedCategory = receivedMaterial.split ("::::")[0] receivedContent7 = receivedMaterial.split ("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update TAGS set characteristic_value ='{receivedContent7}'" f"where item_id='{receivedItemId}' and characteristic_name like'{receivedCategory}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode ( ) receivedCategory = receivedColor.split ("::::")[0] receivedContent7 = receivedColor.split ("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update TAGS set characteristic_value ='{receivedContent7}'" f"where item_id='{receivedItemId}' and characteristic_name like'{receivedCategory}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" return message.encode ( ) receivedCategory = receivedSpecialCarac.split ("::::")[0] receivedContent7 = receivedSpecialCarac.split ("::::")[1] if receivedContent7 != "": result = db_handler._DEBUG_dbCursor.execute ( f"update TAGS set characteristic_value ='{receivedContent7}'" f"where item_id='{receivedItemId}' and characteristic_name like'{receivedCategory}'") db_handler.execute ('commit') if result == []: message = "EDIT FAIL" else: message = "EDIT SUCCESS" return message.encode()