def editProfile(username): img = request.form["img"] info = request.form["info"] level = request.form["level"] age = request.form["age"] asd = fetchone("select pid from registration where username = %s", [username]) sql = "update profile set img = %s, info = %s, level = %s, age = %s where pid = %s" val = (img, info, level, age, asd) update(sql, val)
def check_date(): """ Converts database "date" to same format as date.today() and compares if the date is expired. If date expired = remove match from database. """ current = date.today() current = current.strftime("%a, %d %b %Y") current = datetime.strptime(str(current), "%a, %d %b %Y") result = fetchall("select date from match where matchid > %s", [0]) print(current) for record in result: record = datetime.strptime(record[0], "%a, %d %b %Y") if record < current: print("delete") new_record = record.strftime("%a, %d %b %Y") print(new_record) update("delete from match where date = %s", [new_record])
def change_password(password, new_password): cred = fetchone("select password from registration where username=%s", [session["username"]]) stored_password = cred[0] user_login.verify_password(stored_password, password) if user_login.verify_password(stored_password, password) == True: new_password = user_registration.hash_password(new_password) sql = "update registration set password = %s WHERE username = %s" val = new_password, session["username"] update(sql, val) print("update") return True else: flash("Fel lösenord") return False
def show_chatt(matchid): matchid = int(matchid) print(matchid) antal = request.form["antal"] booked = fetchone("select booked from match where matchid = %s", [matchid]) print(booked[0]) new_booked = int(antal) + booked[0] print(matchid, session["username"]) creatorName = fetchone("select skapare from match where matchid = %s", [matchid]) sql = "insert into booking values(%s,%s,%s)" val = matchid, session["username"], creatorName insert(sql, val) sql = "UPDATE match SET booked = %s WHERE matchid = %s;" val = new_booked, matchid print(matchid, session["username"]) update(sql, val) sql = "UPDATE match SET antal = %s WHERE matchid = %s;" sökes = fetchone("select antal from match where matchid = %s", [matchid]) print(sökes[0]) sökes = sökes[0] - int(antal) val = sökes, matchid update(sql, val) # Future chatt fnction # def sessions(): # return render_template('session.html') # def messageReceived(methods=['GET', 'POST']): # print('message was received!!!') # @socketio.on('my event') # def handle_my_custom_event(json, methods=['GET', 'POST']): # print('received my event: ' + str(json)) # socketio.emit('my response', json, callback=messageReceived) # return render_template('session.html') return start_page()
def booking_game(matchid): matchid = int(matchid) players = request.form["players"] print(players) if players == "0": flash("Var vänlig och boka en plats") print("players = 0" + players) return render_template("match_profile.html", match=show_match.show_Match_Profile(matchid)) else: print("antal högre än 0:" + players) booked = fetchone("select booked from match where matchid = %s", [matchid]) def new_booked(): print(players) if (int(players) + booked[0]) > 4: return "4" else: return int(players) + booked[0] print(matchid, session["username"]) creatorName = fetchone("select creator from match where matchid = %s", [matchid]) sql = "insert into booking values(%s,%s,%s,%s)" val = matchid, session["username"], creatorName, players insert(sql, val) sql = "UPDATE match SET booked = %s WHERE matchid = %s;" val = new_booked(), matchid update(sql, val) sql = "UPDATE match SET players = %s WHERE matchid = %s;" searching = fetchone("select players from match where matchid = %s", [matchid]) print(searching[0]) searching = searching[0] - int(players) val = searching, matchid update(sql, val) return start_page() sql = "UPDATE match SET players = %s WHERE matchid = %s;" searching = fetchone("select players from match where matchid = %s", [matchid]) print(searching[0]) searching = searching[0] - int(players) val = searching, matchid update(sql, val) return start_page()
def operation(self, table): operation_chosen = self.operation_chosen.get() if operation_chosen == "New": self.forget_all() self.label_name.pack() self.new_name.pack() self.label_coord.pack() self.new_coord.pack() self.accept_button.pack() self.accept_button.configure(command=lambda: [ insert(table, self.new_name_value.get(), self.new_coord_value.get()), self.update_values(table), self.window.destroy(), ]) elif operation_chosen == "Update": self.forget_all() self.label_name.pack() self.old_values.pack() self.label_coord.pack() self.new_coord.pack() self.accept_button.pack() self.accept_button.configure(command=lambda: [ update(table, self.old_chosen.get(), self.new_coord_value.get( )), self.update_values(table), self.window.destroy(), ]) elif operation_chosen == "Delete": self.forget_all() self.label_name.pack() self.old_values.pack() self.accept_button.pack() self.accept_button.configure(command=lambda: [ remove(table, self.old_chosen.get()), self.update_values(table), self.window.destroy(), ]) else: raise ValueError return None
def remove_booking(matchid): sql = "select booked from booking where matchid=%s AND username=%s" val = matchid, session["username"] current_booking = fetchone(sql, val) sql = "update match set players=(players+%s) where matchid =%s" val = current_booking, matchid update(sql, val) sql = "update match set booked=(booked-%s) where matchid =%s" val = current_booking, matchid update(sql, val) sql = "delete from booking where matchid=%s AND username=%s" val = matchid, session["username"] update(sql, val) return show_my_games()
import db_operations while True: print """ 1. insert 2. update 3. delete 4. show q. quit """ opt = raw_input("Enter an option:") if opt.lower() == "q" or opt.lower() == "quit": print "thank you!!" break if opt == "1": db_operations.insert() elif opt == "2": db_operations.update() elif opt == "3": db_operations.delete() elif opt == "4": print db_operations.browse() else: print "wrong option"
def remove_match(matchid): update("delete from match where matchid = %s", [matchid]) update("delete from booking where matchid = %s", [matchid]) return show_my_games()
def editProfile(username): asd = fetchone("select pid from registration where username = %s", [username]) oldpic = fetchone("select img from profile where pid = %s", [asd]) img = validatepicture(username) info = request.form["info"] level = request.form["level"] age = request.form["age"] if img == oldpic and age == "" and info == "": print("ifsats 1") sql = "update profile set level = %s where pid = %s" val = (level, asd) update(sql, val) elif img == oldpic and age == "": print("ifsats 2") sql = "update profile set level = %s, info = %s where pid = %s" val = (level, info, asd) update(sql, val) elif img == oldpic: print("ifsats 3") sql = "update profile set level = %s, info = %s, age = %s where pid = %s" val = (level, info, age, asd) update(sql, val) elif img != oldpic and age == "" and info == "": print("ifsats 4") sql = "update profile set level = %s, img = %s where pid =%s" val = (level, img, asd) update(sql, val) elif img != oldpic and age == "": print("ifsats 5") sql = "update profile set level = %s, img = %s, info = %s where pid = %s" val = (level, img, info, asd) update(sql, val) else: print("ifsats 6") sql = "update profile set level = %s, img = %s, info = %s, age = %s where pid =%s" val = (level, img, info, age, asd) update(sql, val) for item in oldpic: if os.path.exists(str(item)): os.remove(str(item.rsplit('/')[3])) print("bild borttagen")