def populate_users(): # Generating Users print("GENERATING USERS") used = [] x = 0 while x < USER_AMOUNT: name = gen_name().rstrip(" ") if name not in used: used.append(name) x += 1 try: user = User( username=name, email=name + gen_email(), password=name, ) log = Logs(user=user) db.session.add(user) db.session.add(log) except Exception as _: pass db.session.commit()
def populate_users(): # Generating Users print("GENERATING USERS") used = [] for x in range(USER_AMOUNT): name = gen_name().rstrip(" ") if name not in used: used.append(name) try: user = User( username=name, email=name + gen_email(), password=bcrypt.generate_password_hash(name).decode( "utf-8"), ) log = Logs(user=user, ) db.session.add(user) db.session.add(log) if x % 5 == 0: db.session.commit() except Exception as _: pass db.session.commit()
def scoreboard(): usersScores = User.get_all() usersScores.sort(reverse=True, key=lambda user: user.points(id=user.id)) return render_template("scoreboard.html", scores=usersScores)
db.session.add(ch1) with app.app_context(): s = Settings.query.get(1) a = User.query.filter_by(username="******").first() if s or a: print( "populate_db.prod: Skipping since, database is already populated!") exit() now_time = datetime.now(pytz.utc) admin_user = User( username="******", email=handle_admin_email(), password=handle_admin_pass(), isAdmin=True, ) db.session.add(admin_user) admin_log = Logs( user=admin_user, accountCreationTime=now_time, visitedMachine=True, machineVisitTime=now_time, ) db.session.add(admin_log) db.session.add(Settings(dummy=True)) populate_tags()
difficulty="easy", category=Category.query.get(2), tags=[Tag.query.get(1), Tag.query.get(2)], ) db.session.add(ch1) with app.app_context(): db.create_all() default_time = datetime.now(pytz.utc) passwd = handle_admin_pass() admin_user = User( username="******", email=handle_admin_email(), password=bcrypt.generate_password_hash(passwd).decode("utf-8"), isAdmin=True, ) db.session.add(admin_user) admin_log = Logs( user=admin_user, accountCreationTime=default_time, visitedMachine=True, machineVisitTime=default_time, ) db.session.add(admin_log) db.session.add(Settings(dummy=True)) populate_tags()