Best Python code snippet using dbt-osmosis_python
Main.py
Source:Main.py
...61 password = request.values.get("password")62 email = request.values.get("email")63 ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)64 if not userName or not password or not email or len(userName) > 15 or not bool(re.match("^[A-Za-z0-9]*$", userName)): return "-1"65 cursor = execute_sql("select mail_domain from banned_mails")66 banned_mails = cursor.fetchall()67 for mail in banned_mails:68 if mail[0].lower() in email.lower():69 return "-1"70 cursor = execute_sql("select null from accounts where name = %s or email = %s", [userName, email])71 if cursor.rowcount > 0:72 return "-2"73 if ip is not None and ip != "127.0.0.1":74 cursor = execute_sql("select null from register_ips where ip = %s", [ip])75 if cursor.rowcount == 0:76 cursor = execute_sql("insert into register_ips (ip) values (%s)", [ip])77 else:78 return "-1"79 cipher_suite = Fernet(encryption_key)80 encrypted_password = cipher_suite.encrypt(password.encode())81 verify_token = generate_token()82 cursor = execute_sql("insert into accounts (name,password,email,ip,verify_token,created_on) values (%s,%s,%s,%s,%s,%s)", [userName, encrypted_password, email, request.remote_addr, verify_token, int(time.time())])83 html = f"""\84 <html>85 <body>86 <p>Thank you for creating an account on UltimateGDPS! To activate your account, click the link below:<br>87 <br>88 <a href="https://ultimategdps.mathieuar.fr/auth/verify-account.php?user_name={userName}&verify_token={verify_token}">Verify account</a> 89 </p>90 <p>You are receiving this email because you have created an account on UltimateGDPS</p>91 </body>92 </html>93 """94 threading.Thread(target=send_mail, args=[email, html], daemon=True).start()95 #send_mail(email, html)96 return "1"97@app.route(f"{flask_path}/accounts/loginGJAccount.php", methods=["POST"])98async def loginAccount():99 userName = request.values.get("userName")100 password = request.values.get("password")101 admin_panel = request.values.get("admin_panel")102 if not userName or not password:103 return "-1"104 cursor = execute_sql("select id,password,ban_account from accounts where name = %s", [userName])105 if cursor.rowcount == 0:106 return "-1"107 account_info = cursor.fetchall()[0]108 if account_info[2] == 1:109 if admin_panel != "yes":110 return "-12"111 encrypted_password = account_info[1]112 cipher_suite = Fernet(encryption_key)113 decrypted_password = cipher_suite.decrypt(encrypted_password.encode()).decode()114 if password != decrypted_password:115 return "-1"116 accID = account_info[0]117 if admin_panel == "yes":118 return "1"119 return f"{accID},{accID}"120@app.route(f"{flask_path}/getGJUserInfo20.php", methods=["POST"])121async def getUserInfos():122 targetAccountID = request.values.get("targetAccountID")123 accountID = request.values.get("accountID")124 125 cursor = execute_sql("select null from blocked where user_id = %s and blocked_user_id = %s", [targetAccountID, accountID])126 if cursor.rowcount > 0: return "-1"127 extra_params = None128 cursor = execute_sql("select name,id,coins,user_coins,color1,color2,stars,diamonds,demons,creator_points,privatemsg_status,friendsreq_status,commenthist_status,yt_url,icon_cube,icon_ship,icon_ball,icon_ufo,icon_wave,icon_robot,icon_glow,icon_spider,icon_explosion,twitter_url,twitch_url,verified,ban_account,role from accounts where id = %s", [targetAccountID])129 if cursor.rowcount == 0:130 return "-1"131 infos = cursor.fetchall()[0]132 cursor = execute_sql("SELECT null FROM accounts WHERE stars > %s AND ban_leaderboard = 0 and ban_account = 0 and verified = 1", [infos[6]])133 rank = cursor.rowcount + 1134 mod_badge = 0135 cursor = execute_sql("select badge from roles where id = %s", [infos[27]])136 if cursor.rowcount == 1:137 mod_badge = cursor.fetchall()[0][0]138 if targetAccountID == accountID:139 cursor = execute_sql("select null from private_messages where to_id = %s and is_new = 1", [accountID])140 total_new_msg = cursor.rowcount141 new_friend_count = 0142 cursor = execute_sql("select null from friends where friend1 = %s and is_new1 = 1", [accountID])143 new_friend_count += cursor.rowcount144 cursor = execute_sql("select null from friends where friend2 = %s and is_new2 = 1", [accountID])145 new_friend_count += cursor.rowcount146 cursor = execute_sql("select null from friend_requests where req_user_id = %s and is_new = 1", [accountID])147 friend_requests = cursor.rowcount148 extra_params = f":38:{total_new_msg}:39:{friend_requests}:40:{str(new_friend_count)}"149 if infos[26] == 1:150 return f"1:{infos[0]}:2:{infos[1]}:13:{infos[2]}:17:0:10:0:11:3:3:0:46:{infos[7]}:4:0:8:0:18:2:19:1:50:2:21:{infos[14]}:22:{infos[15]}:23:{infos[16]}:24:{infos[17]}:25:{infos[18]}:26:{infos[19]}:28:{infos[20]}:43:{infos[21]}:47:{infos[22]}:30:0:16:{infos[1]}:31:0:29:0:49:{mod_badge}"151 return f"1:{infos[0]}:2:{infos[1]}:13:{infos[2]}:17:{infos[3]}:10:{infos[4]}:11:{infos[5]}:3:{infos[6]}:46:{infos[7]}:4:{infos[8]}:8:{infos[9]}:18:{infos[10]}:19:{infos[11]}:50:{infos[12]}:20:{infos[13]}:21:{infos[14]}:22:{infos[15]}:23:{infos[16]}:24:{infos[17]}:25:{infos[18]}:26:{infos[19]}:28:{infos[20]}:43:{infos[21]}:47:{infos[22]}:30:{rank}:16:{infos[1]}:31:0:44:{infos[23]}:45:{infos[24]}:29:{infos[25]}:49:{mod_badge}{extra_params}"152@app.route(f"{flask_path}/getGJAccountComments20.php", methods=["POST"])153async def getUserProfileComments():154 print("entré dans getprofilecomment")155 accountID = request.values.get("accountID")156 page = request.values.get("page")157 commentpage = int(page)*10158 cursor = execute_sql("select ban_account,ban_profilemsg,verified,ban_account_reason from accounts where id = %s", [accountID])159 if cursor.rowcount == 0:160 return "-1"161 ban_checks = cursor.fetchall()[0]162 is_accbanned = ban_checks[0]163 is_profilemsgbanned = ban_checks[1]164 is_verified = ban_checks[2]165 ban_account_reason = ban_checks[3]166 if is_accbanned == 1:167 message = f"**Ultimate GDPS** This account is banned. Reason: {ban_account_reason}"168 message = message.encode("ascii")169 message = base64.b64encode(message).decode()170 return f"2~{message}~3~{accountID}~4~test~5~0~7~0~9~Message from Ultimate GDPS#1:0:10"171 if is_profilemsgbanned == 1:172 message = "KipVbHRpbWF0ZSBHRFBTKiogVGhpcyBhY2NvdW50IGlzIG5vdCB2ZXJpZmllZC4gSWYgeW91IGFyZSB0aGUgb3duZXIgb2YgdGhpcyBhY2NvdW50IHlvdSBjYW4gYWN0aXZhdGUgaXQgd2l0aCB0aGUgbGluayBzZW50IHRvIHlvdXIgZW1haWxzLg=="173 return f"2~{message}~3~{accountID}~4~test~5~0~7~0~9~Message from Ultimate GDPS#1:0:10"174 if is_verified == 0:175 message = "**Ultimate GDPS** This account is not verified. If you are the owner of this account you can activate it with the link sent to your emails or it will get deleted in the next 15 minutes."176 message = message.encode("ascii")177 message = base64.b64encode(message).decode()178 return f"2~{message}~3~{accountID}~4~test~5~0~7~0~9~Message from Ultimate GDPS\x04#1:0:10"179 cursor = execute_sql("select comment,likes,is_spam,id,posted_on from acc_comments where account_id = %s order by posted_on desc limit 10 offset %s", [accountID, commentpage])180 comm_count = cursor.rowcount181 if comm_count == 0:182 return "#0:0:0"183 comments_list = cursor.fetchall()184 comments = ""185 for comm in comments_list:186 comments = f"{comments}2~{comm[0]}~3~{accountID}~4~{comm[1]}~5~0~7~{comm[2]}~9~{comm[4]}~6~{comm[3]}|"187 return f"{comments}#{comm_count}:{commentpage}:10"188@app.route(f"{flask_path}/uploadGJAccComment20.php", methods=["POST"])189async def uploadProfileComment():190 comment = request.values.get("comment")191 accountID = request.values.get("accountID")192 gjp = request.values.get("gjp")193 gjp_check = check_gjp(accountID, gjp)194 if not gjp_check:195 return "-1"196 cursor = execute_sql("insert into acc_comments (account_id,comment) values (%s,%s)", [accountID, comment])197 return "1"198@app.route(f"{flask_path}/getGJUsers20.php", methods=["POST"])199async def getUsers():200 str = request.values.get("str")201 page = request.values.get("page")202 usrpage = int(page)*10203 cursor = execute_sql("SELECT name,id,coins,user_coins,icon_cube,color1,color2,icon_type,special,stars,creator_points,demons FROM accounts WHERE id = %s OR name LIKE CONCAT('%', %s, '%') ORDER BY stars DESC LIMIT 10 OFFSET %s", [str, str, usrpage])204 user_count = cursor.rowcount205 if user_count == 0:206 return "-1"207 users_list = ""208 users = cursor.fetchall()209 count = 1210 for user in users:211 users_list = f"{users_list}1:{user[0]}:2:{user[1]}:13:{user[2]}:17:{user[3]}:9:{user[4]}:10:{user[5]}:11:{user[6]}:14:{user[7]}:15:{user[8]}:16:{user[1]}:3:{user[9]}:8:{user[10]}:4:{user[11]}"212 if count != user_count:213 users_list = users_list + "|"214 count =+ 1215 return f"{users_list}#{user_count}:{usrpage}:10"216@app.route(f"{flask_path}/updateGJUserScore22.php", methods=["POST"])217async def updateUserScore():218 accountID = request.values.get("accountID")219 gjp = request.values.get("gjp")220 coins = request.values.get("coins")221 stars = request.values.get("stars")222 demons = request.values.get("demons")223 icon = request.values.get("icon")224 color1 = request.values.get("color1")225 color2 = request.values.get("color2")226 iconType = request.values.get("iconType")227 userCoins = request.values.get("userCoins")228 special = request.values.get("special")229 accIcon = request.values.get("accIcon")230 accShip = request.values.get("accShip")231 accBall = request.values.get("accBall")232 accBird = request.values.get("accBird")233 accDart = request.values.get("accDart")234 accRobot = request.values.get("accRobot")235 accGlow = request.values.get("accGlow")236 accSpider = request.values.get("accSpider")237 accExplosion = request.values.get("accExplosion")238 diamonds = request.values.get("diamonds")239 cursor = execute_sql("select verified from accounts where id = %s", [accountID])240 is_verified = cursor.fetchall()[0][0]241 if is_verified == 0: return accountID242 gjp_check = check_gjp(accountID, gjp)243 if not gjp_check:244 return "-1"245 246 values = [coins, stars, demons, icon, color1, color2, iconType, userCoins, special, accIcon, accShip, accBall, accBird, accDart, accRobot, accGlow, request.remote_addr, accSpider, accExplosion, diamonds, accountID]247 for value in values:248 if value is None:249 return "-1"250 cursor = execute_sql("update accounts set coins=%s,stars=%s,demons=%s,icon=%s,color1=%s,color2=%s,icon_type=%s,user_coins=%s,special=%s,icon_cube=%s,icon_ship=%s,icon_ball=%s,icon_ufo=%s,icon_wave=%s,icon_robot=%s,icon_glow=%s,ip=%s,icon_spider=%s,icon_explosion=%s,diamonds=%s where id = %s", values)251 return accountID252@app.route(f"{flask_path}/getGJScores20.php", methods=["POST"])253async def getLeaderboardScores():254 accountID = request.values.get("accountID")255 gjp = request.values.get("gjp")256 type = request.values.get("type")257 cursor = execute_sql("select ban_account,verified,stars from accounts where id = %s", [accountID])258 infos = cursor.fetchall()[0]259 is_banned =infos[0]260 is_verified = infos[1]261 stars = infos[2]262 if is_banned == 1:263 return "-1"264 gjp_check = check_gjp(accountID, gjp)265 if not gjp_check:266 return "-1"267 users_list = None268 needed_infos = "name,id,coins,user_coins,icon,color1,color2,icon_type,special,stars,creator_points,demons,diamonds"269 count = 1270 print(type)271 if type == "top":272 cursor = execute_sql("SELECT " + needed_infos + " FROM accounts WHERE ban_leaderboard = 0 and verified = '1' AND stars > '0' ORDER BY stars DESC LIMIT 100")273 users_list = cursor.fetchall()274 elif type == "creators":275 cursor = execute_sql("SELECT " + needed_infos + " FROM accounts WHERE ban_leaderboard = 0 and verified = '1' and creator_points > '0' ORDER BY creator_points DESC LIMIT 100")276 users_list = cursor.fetchall()277 elif type == "relative":278 if is_verified == 0:279 return "-1"280 users_list = []281 cursor = execute_sql("SELECT id FROM accounts WHERE stars > %s AND ban_leaderboard = 0 and ban_account = 0 and verified = 1 ORDER BY stars DESC", [stars])282 total_up = cursor.fetchall()283 cursor = execute_sql("SELECT " + needed_infos + " FROM accounts WHERE stars > %s AND ban_leaderboard = 0 and verified = 1 and id != %s ORDER BY stars DESC LIMIT 50", [stars, accountID])284 if cursor.rowcount > 0:285 users_list = cursor.fetchall()286 for id in total_up:287 if id[0] == users_list[0][1]:288 break289 count += 1290 cursor = execute_sql("select " + needed_infos + " from accounts where id = %s", [accountID])291 users_list.append(cursor.fetchall()[0])292 cursor = execute_sql("SELECT " + needed_infos + " FROM accounts WHERE stars <= %s AND ban_leaderboard = 0 and verified = 1 and id != %s ORDER BY stars DESC LIMIT 50", [stars, accountID])293 if cursor.rowcount > 0:294 users_list.append(cursor.fetchall()[0])295 elif type == "friends":296 cursor = execute_sql("select friend1,friend2 from friends where friend1 = %s or friend2 = %s", [accountID, accountID])297 if cursor.rowcount == 0: return "-1"298 friends_list = cursor.fetchall()299 friends = f"{accountID}"300 for friend in friends_list:301 friend_id = friend[0]302 if str(friend[0]) == accountID:303 friend_id = friend[1]304 friends = f"{friends},{friend_id}"305 cursor = execute_sql("SELECT " + needed_infos + " FROM accounts WHERE ban_leaderboard = 0 and verified = 1 and id in (" + friends + ") ORDER BY stars DESC")306 users_list = cursor.fetchall()307 else:308 return "-1"309 if users_list is None:310 return "-1"311 lead_list = ""312 for user in users_list:313 lead_list = f"{lead_list}1:{user[0]}:2:{user[1]}:13:{user[2]}:17:{user[3]}:6:{count}:9:{user[4]}:10:{user[5]}:11:{user[6]}:14:{user[7]}:15:{user[8]}:16:{user[1]}:3:{user[9]}:8:{user[10]}:4:{user[11]}:7:{user[1]}:46:{user[12]}|"314 count += 1315 return lead_list316@app.route(f"{flask_path}/uploadGJLevel21.php", methods=["POST"])317async def uploadLevel():318 gjp = request.values.get("gjp")319 gameVersion = request.values.get("gameVersion")320 levelDesc = request.values.get("levelDesc")321 levelName = request.values.get("levelName")322 levelString = request.values.get("levelString")323 levelVersion = request.values.get("levelVersion")324 levelLength = request.values.get("levelLength")325 audioTrack = request.values.get("audioTrack")326 password = request.values.get("password")327 original = request.values.get("original")328 twoPlayer = request.values.get("twoPlayer")329 songID = request.values.get("songID")330 objects = request.values.get("objects")331 coins = request.values.get("coins")332 requestedStars = request.values.get("requestedStars")333 unlisted = request.values.get("unlisted")334 ldm = request.values.get("ldm")335 accountID = request.values.get("accountID")336 levelInfo = request.values.get("levelInfo")337 binaryVersion = request.values.get("binaryVersion")338 extraString = request.values.get("extraString")339 gjp_check = check_gjp(accountID, gjp)340 if not gjp_check:341 return "-1"342 args = [levelName, gameVersion, binaryVersion, levelString, levelDesc, levelVersion, levelLength, audioTrack, password, original, twoPlayer, songID, objects, coins, requestedStars, extraString, levelInfo, accountID, unlisted, ldm]343 344 cursor = execute_sql("SELECT id FROM levels WHERE name = %s AND author_id = %s", [levelName, accountID])345 level_id = None346 try:347 level_id = cursor.fetchall()[0][0]348 except:349 pass350 if cursor.rowcount == 0:351 cursor = execute_sql("insert into levels (name,game_version,binary_version,level_content,description,version,length,official_song,password,original,dual_mode,custom_song,objects,coins,requested_rate,extra_content,level_info,author_id,unlisted,ldm) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", args)352 cursor = execute_sql("SELECT id FROM levels WHERE name = %s AND author_id = %s", [levelName, accountID])353 level_id = cursor.fetchall()[0][0]354 elif cursor.rowcount == 1:355 cursor = execute_sql("update levels set game_version=%s,binary_version=%s,level_content=%s,description=%s,version = version + 1,length=%s,official_song=%s,password=%s,dual_mode=%s,custom_song=%s,objects=%s,coins=%s,requested_rate=%s,extra_content=%s,level_info=%s,unlisted=%s,ldm=%s where id = %s", [gameVersion, binaryVersion, levelString, levelDesc, levelLength, audioTrack, password, twoPlayer, songID, objects, coins, requestedStars, extraString, levelInfo, unlisted, ldm, level_id])356 else:357 return "-1"358 return str(level_id)359@app.route(f"{flask_path}/getGJLevels21.php", methods=["POST"])360async def getLevels():361 gd_type = request.values.get("type")362 accountID = request.values.get("accountID")363 gd_str = request.values.get("str")364 page = 0365 if "page" in request.values:366 page = int(request.values.get("page"))*10367 gauntlet_id = request.values.get("gauntlet")368 gauntlet = False369 if gauntlet_id is not None and gauntlet_id != "": gauntlet = True370 print(request.values)371 levels = ""372 users = ""373 songs = ""374 all_levels = ""375 count = 0376 total_levels = 0377 lvl_ids = []378 needed_infos = "id,name,version,author_id,difficulty,downloads,official_song,game_version,likes,demon,demon_difficulty,auto,stars,featured,epic,objects,description,length,original,coins,coins_verified,requested_rate,ldm,custom_song"379 if gd_type == "0":380 gd_str = f"%{gd_str}%"381 base_query = " from levels where name like %s or id like %s"382 cursor = execute_sql("select null" + base_query, [gd_str, gd_str])383 if cursor.rowcount == 0: return "-1"384 else: total_levels = cursor.rowcount385 cursor = execute_sql("select " + needed_infos + base_query + " order by downloads desc limit 10 offset %s", [gd_str, gd_str, page])386 elif gd_type == "1":387 base_query = " from levels where unlisted != 1"388 cursor = execute_sql("select null" + base_query)389 if cursor.rowcount == 0: return "-1"390 else: total_levels = cursor.rowcount391 cursor = execute_sql("select " + needed_infos + base_query + " order by downloads desc limit 10 offset %s", [page])392 elif gd_type == "2":393 base_query = " from levels where unlisted != 1"394 cursor = execute_sql("select null" + base_query)395 if cursor.rowcount == 0: return "-1"396 else: total_levels = cursor.rowcount397 cursor = execute_sql("select " + needed_infos + base_query + " order by likes desc limit 10 offset %s", [page])398 elif gd_type == "4":399 base_query = " from levels where unlisted != 1"400 cursor = execute_sql("select null" + base_query)401 if cursor.rowcount == 0: return "-1"402 else: total_levels = cursor.rowcount403 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date desc limit 10 offset %s", [page])404 elif gd_type == "5":405 base_query = " from levels where author_id = %s"406 cursor = execute_sql("select null" + base_query, [gd_str])407 if cursor.rowcount == 0: return "-1"408 else: total_levels = cursor.rowcount409 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date limit 10 offset %s", [gd_str, page])410 elif gd_type == "6":411 base_query = " from levels where unlisted != 1 and featured = 1"412 cursor = execute_sql("select null" + base_query)413 if cursor.rowcount == 0: return "-1"414 else: total_levels = cursor.rowcount415 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date limit 10 offset %s", [page])416 elif gd_type == "7":417 base_query = " from levels where unlisted != 1 and objects > 9999"418 cursor = execute_sql("select null" + base_query)419 if cursor.rowcount == 0: return "-1"420 else: total_levels = cursor.rowcount421 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date limit 10 offset %s", [page])422 elif gd_type == "10":423 check = re.match(r"^[0-9,]*$", gd_str)424 if not check: return "-1"425 base_query = " from levels where id in (" + gd_str + ")"426 cursor = execute_sql("select null" + base_query)427 if cursor.rowcount == 0: return "-1"428 else: total_levels = cursor.rowcount429 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date limit 10 offset %s", [page])430 elif gd_type == "11":431 base_query = " from levels where unlisted != 1 and stars > 0"432 cursor = execute_sql("select null" + base_query)433 if cursor.rowcount == 0: return "-1"434 else: total_levels = cursor.rowcount435 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date limit 10 offset %s", [page])436 elif gd_type == "16":437 base_query = " from levels where unlisted != 1 and epic > 0"438 cursor = execute_sql("select null" + base_query)439 if cursor.rowcount == 0: return "-1"440 else: total_levels = cursor.rowcount441 cursor = execute_sql("select " + needed_infos + base_query + " order by upload_date limit 10 offset %s", [page])442 elif gauntlet:443 base_query = " from levels where id = %s"444 cursor = execute_sql("select lvl1,lvl2,lvl3,lvl4,lvl5 from gauntlets where id = %s", [gauntlet_id])445 if cursor.rowcount == 0: return "-1"446 total_levels = 5447 gl_levels = cursor.fetchall()[0]448 cursor = execute_sql("select " + needed_infos + base_query + " union select " + needed_infos + base_query + " union select " + needed_infos + base_query + " union select " + needed_infos + base_query + " union select " + needed_infos + base_query, [gl_levels[0],gl_levels[1],gl_levels[2],gl_levels[3],gl_levels[4]])449 else:450 return "-1"451 all_levels = cursor.fetchall()452 scount = 0453 for lvl in all_levels:454 if lvl[23] > 0:455 scount += 1456 rs_count = 0457 for lvl in all_levels:458 count += 1459 levels = f"{levels}1:{lvl[0]}:2:{lvl[1]}:5:{lvl[2]}:6:{lvl[3]}:8:10:9:{lvl[4]}:10:{lvl[5]}:12:{lvl[6]}:13:{lvl[7]}:14:{lvl[8]}:17:{lvl[9]}:43:{lvl[10]}:25:{lvl[11]}:18:{lvl[12]}:19:{lvl[13]}:42:{lvl[14]}:45:{lvl[15]}:3:{lvl[16]}:15:{lvl[17]}:30:{lvl[18]}:31:0:37:{lvl[19]}:38:{lvl[20]}:39:{lvl[21]}:46:1:47:2:40:{lvl[22]}:35:{lvl[23]}"460 if gauntlet: levels = f"{levels}:44:{gauntlet_id}"461 author_name = get_user_name(lvl[3])462 author_id = lvl[3]463 if author_name is None:464 author_name = ""465 author_id = "0"466 users = f"{users}{lvl[3]}:{author_name}:{author_id}"467 lvl_ids.append(lvl[0])468 song_id = lvl[23]469 if song_id > 0:470 encoded_song = get_encode_song(song_id)471 if "~" in encoded_song:472 songs = f"{songs}{encoded_song}"473 rs_count += 1474 if count != len(all_levels):475 levels = levels + "|"476 users = users + "|"477 if song_id > 0 and "~" in encoded_song and rs_count < scount:478 songs = songs + "~:~"479 cursor = execute_sql("select null from levels")480 count = cursor.rowcount481 if page == 0:482 page = "00"483 levels_hash = get_levels_hash(lvl_ids)484 response = f"{levels}#{users}#{songs}#{total_levels}:{page}:10#{levels_hash}"485 return response486@app.route(f"{flask_path}/getGJSongInfo.php", methods=["POST"])487async def getSongInfos():488 songID = request.values.get("songID")489 return get_encode_song(songID)490@app.route(f"{flask_path}/downloadGJLevel22.php", methods=["POST"])491async def downloadLevel():492 levelID = request.values.get("levelID")493 accountID = request.values.get("accountID")494 gjp = request.values.get("gjp")495 print(request.values)496 if accountID is not None and accountID != "":497 gjp_check = check_gjp(accountID, gjp)498 if gjp_check: 499 cursor = execute_sql("select null from actions where value1 = %s and value2 = %s and type = 'download'", [accountID, levelID])500 if cursor.rowcount == 0:501 cursor = execute_sql("update levels set downloads = downloads + 1 where id = %s", [levelID])502 cursor = execute_sql("insert into actions (type,value1,value2) values (%s,%s,%s)", ["download", accountID, levelID])503 cursor = execute_sql("select id,name,description,level_content,version,author_id,difficulty,downloads,official_song,game_version,likes,demon,demon_difficulty,auto,stars,featured,epic,objects,length,original,upload_date,update_date,custom_song,extra_content,coins,coins_verified,requested_rate,ldm,password from levels where id = %s", [levelID])504 if cursor.rowcount == 0:505 return "-1"506 lvl_infos = cursor.fetchall()[0]507 lvl_string = lvl_infos[3]508 level_pass = lvl_infos[28]509 xorpass = 0510 if level_pass != 0:511 xorpass = b64_encode(xor_cipher(str(level_pass), "26364"))512 upload_date = "19-10-2021 15-42"513 update_date = "blopu"514 response = f"1:{lvl_infos[0]}:2:{lvl_infos[1]}:3:{lvl_infos[2]}:4:{lvl_infos[3]}:5:{lvl_infos[4]}:6:{lvl_infos[5]}:8:10:9:{lvl_infos[6]}:10:{lvl_infos[7]}:11:1:12:{lvl_infos[8]}:13:{lvl_infos[9]}:14:{lvl_infos[10]}:17:{lvl_infos[11]}:43:{lvl_infos[12]}:25:{lvl_infos[13]}:18:{lvl_infos[14]}:19:{lvl_infos[15]}:42:{lvl_infos[16]}:45:{lvl_infos[17]}:15:{lvl_infos[18]}:30:{lvl_infos[19]}:31:1:28:{upload_date}:29:{update_date}:35:{lvl_infos[22]}:36:{lvl_infos[23]}:37:{lvl_infos[24]}:38:{lvl_infos[25]}:39:{lvl_infos[26]}:46:1:47:2:48:1:40:{lvl_infos[27]}:27:{xorpass}"515 encoded_string = get_encoded_lvlstring(lvl_string)516 lvl_moreinfos = f"{lvl_infos[5]},{lvl_infos[14]},{lvl_infos[11]},{lvl_infos[0]},{lvl_infos[25]},{lvl_infos[15]},{lvl_infos[28]},0"517 encoded_lvlinfos = sha1(f"{lvl_moreinfos}xI25fpAapCQg".encode()).hexdigest()518 cursor = execute_sql("select name from accounts where id = %s", [lvl_infos[5]])519 return f"{response}#{encoded_string}#{encoded_lvlinfos}#{lvl_moreinfos}"520@app.route(f"{flask_path}/requestUserAccess.php", methods=["POST"])521async def modReq():522 accountID = request.values.get("accountID")523 gjp = request.values.get("gjp")524 525 gjp_check = check_gjp(accountID, gjp)526 if not gjp_check:527 return "-1"528 cursor = execute_sql("select role from accounts where id = %s", [accountID])529 if cursor.rowcount == 0:530 return "-1"531 role_id = cursor.fetchall()[0][0]532 cursor = execute_sql("select badge from roles where id = %s", [role_id])533 if cursor.rowcount == 0:534 return "-1"535 badge_id = cursor.fetchall()[0][0]536 if badge_id == 0:537 return "-1"538 elif badge_id == 1:539 return "1"540 elif badge_id > 1:541 return "2"542 else:543 return "-1"544@app.route(f"{flask_path}/suggestGJStars20.php", methods=["POST"])545async def ModSents():546 print("oui")547 accountID = request.values.get("accountID")548 gjp = request.values.get("gjp")549 levelID = request.values.get("levelID")550 stars = int(request.values.get("stars"))551 feature = int(request.values.get("feature"))552 demon = 0553 auto = 0554 difficulty = 0555 gjp_check = check_gjp(accountID, gjp)556 if not gjp_check:557 return "-1"558 cursor = execute_sql("select role from accounts where id = %s", [accountID])559 if cursor.rowcount == 0:560 return "-1"561 role_id = cursor.fetchall()[0][0]562 cursor = execute_sql("select perm_suggest,perm_rate from roles where id = %s", [role_id])563 if cursor.rowcount == 0:564 return "-1"565 perms = cursor.fetchall()[0]566 data = {}567 image = ""568 if perms[1] == 1:569 if stars == 1:570 auto = 1571 image = "auto"572 elif stars == 2:573 difficulty = 10574 image = "easy"575 elif stars == 3:576 difficulty = 20577 image = "normal"578 elif stars == 4 or stars == 5:579 difficulty = 30580 image = "hard"581 elif stars == 6 or stars == 7:582 difficulty = 40583 image = "harder"584 elif stars == 8 or stars == 9:585 difficulty = 50586 image = "insane"587 elif stars == 10:588 demon = 1589 image = "demon-hard"590 if feature == 1:591 image = f"{image}-featured"592 cursor = execute_sql("select id,name,author_id,downloads,likes,length,description,stars from levels where id = %s", [levelID])593 if cursor.rowcount == 0:594 return "-1"595 lvl_infos = cursor.fetchall()[0]596 cursor = execute_sql("update levels set stars = %s, featured = %s, demon = %s, auto = %s, difficulty = %s where id = %s", [stars, feature, demon, auto, difficulty, levelID])597 print(lvl_infos)598 def send_discord_message():599 cursor = execute_sql("select name from accounts where id = %s", [lvl_infos[2]])600 author_name = cursor.fetchall()[0][0]601 already_rated = False602 if lvl_infos[7] > 0:603 already_rated = True604 time = lvl_infos[5]605 if lvl_infos[6] == "":606 description = "No description provided"607 else:608 description = b64_decode(lvl_infos[6])609 length = "Unknown"610 if time == 0:611 length = "Tiny"612 elif time == 1:613 length = "Short"614 elif time == 2:615 length = "Medium"616 elif time == 3:617 length = "Long"618 elif time == 4:619 length = "XL"620 title = "A new level got rated!"621 if already_rated:622 title = "A level got its rating updated!"623 data = {"embeds": [{"title": title,624 "description" : f"<:play:900086729120292974> **{lvl_infos[1]}** by {author_name} \n<:comment:900091546299424838> {description} \n<:time:900085839399362570> {length} \n<:download:900085215312093194> {lvl_infos[3]} \n<:like:900085517520109599> {lvl_infos[4]} \nð {lvl_infos[0]}",625 "color": 65280,626 "thumbnail": {"url": f"https://mathieuar.fr/gdps_assets/{image}.png"}}]}627 requests.post(rate_update_webhook, json = data)628 threading.Thread(target=send_discord_message, daemon=True).start()629 return "1"630@app.route(f"{flask_path}/uploadGJComment21.php", methods=["POST"])631async def uploadLvlComment():632 accountID = request.values.get("accountID")633 gjp = request.values.get("gjp")634 comment = request.values.get("comment")635 percent = request.values.get("percent")636 levelID = request.values.get("levelID")637 gjp_check = check_gjp(accountID, gjp)638 if not gjp_check:639 return "-1"640 if comment is None or accountID is None:641 return "-1"642 if percent is None:643 percent = 0644 cursor = execute_sql("insert into lvl_comments (author_id,comment,percent,level_id) values (%s,%s,%s,%s)", [accountID, comment, percent, levelID])645 return "1"646@app.route(f"{flask_path}/deleteGJComment20.php", methods=["POST"])647async def deleteLvlComment():648 accountID = request.values.get("accountID")649 gjp = request.values.get("gjp")650 commentID = request.values.get("commentID")651 levelID = request.values.get("levelID")652 gjp_check = check_gjp(accountID, gjp)653 if not gjp_check:654 return "-1"655 cursor = execute_sql("delete from lvl_comments where id = %s and level_id = %s and author_id = %s", [commentID, levelID, accountID])656 return "1"657@app.route(f"{flask_path}/getGJComments21.php", methods=["POST"])658@app.route(f"{flask_path}/getGJCommentHistory.php", methods=["POST"])659async def getLvlComments():660 print("ok")661 mode = request.values.get("mode")662 levelID = request.values.get("levelID")663 userID = request.values.get("userID")664 page = int(request.values.get("page"))665 count = request.values.get("count")666 if count is None or count == "": count = 10667 count = int(count)668 offset = page*count669 order = "uploaded_on"670 selected_row = "level_id"671 wanted_id = levelID672 if userID is not None and userID != "":673 selected_row = "author_id"674 wanted_id = userID675 if mode == 1:676 order = "likes"677 cursor = execute_sql("select id,uploaded_on,comment,author_id,likes,is_spam,percent,level_id from lvl_comments where " + selected_row + " = %s order by %s desc limit %s offset %s", [wanted_id, order, count, offset])678 if cursor.rowcount == 0:679 return "-2"680 comments = cursor.fetchall()681 comment_string = ""682 total_comm = cursor.rowcount683 count = 1684 for comm in comments:685 cursor = execute_sql("select role,comment_color,name,icon,color1,color2,icon_type,special from accounts where id = %s", [comm[3]])686 user_info = cursor.fetchall()[0]687 badge = "0"688 if user_info[0] != 9999:689 cursor = execute_sql("select badge from roles where id = %s", [user_info[0]])690 badge = cursor.fetchall()[0][0]691 if selected_row == "author_id":692 comment_string = f"{comment_string}1~{comm[7]}~"693 comment_string = f"{comment_string}2~{comm[2]}~3~{comm[3]}~4~{comm[4]}~5~0~7~{comm[5]}~9~{comm[1]}~6~{comm[0]}~10~{comm[6]}~11~{badge}~12~{user_info[1]}:1~{user_info[2]}~7~1~9~{user_info[3]}~10~{user_info[4]}~11~{user_info[5]}~14~{user_info[6]}~15~{user_info[7]}~16~{comm[3]}"694 if count < total_comm:695 comment_string = f"{comment_string}|"696 count += 1697 cursor = execute_sql("select null from levels where id = %s", [levelID])698 total_count = cursor.rowcount699 return f"{comment_string}#{total_count}:{offset}:{total_count}"700@app.route(f"{flask_path}/updateGJAccSettings20.php", methods=["POST"])701async def updateProfile():702 accountID = request.values.get("accountID")703 gjp = request.values.get("gjp")704 msg = request.values.get("mS")705 friend = request.values.get("frS")706 msg_hist = request.values.get("cS")707 yt = request.values.get("yt")708 twitch = request.values.get("twitch")709 twitter = request.values.get("twitter")710 gjp_check = check_gjp(accountID, gjp)711 if not gjp_check:712 return "-1"713 print(request.values)714 cursor = execute_sql("update accounts set privatemsg_status=%s,friendsreq_status=%s,commenthist_status=%s,yt_url=%s,twitch_url=%s,twitter_url=%s where id = %s", [msg, friend, msg_hist, yt, twitch, twitter, accountID])715 return "1"716@app.route(f"{flask_path}/likeGJItem211.php", methods=["POST"])717async def like():718 accountID = request.values.get("accountID")719 type = int(request.values.get("type"))720 itemID = request.values.get("itemID")721 like = int(request.values.get("like"))722 gjp = request.values.get("gjp")723 print(request.values)724 gjp_check = check_gjp(accountID, gjp)725 action_type = None726 table = None727 if not gjp_check:728 return "-1"729 if type == 1:730 action_type = "lvl_like"731 table = "levels"732 elif type == 2:733 action_type = "lvlcomm_like"734 table = "lvl_comments"735 elif type == 3:736 action_type = "acccomm_like"737 table = "acc_comments"738 else:739 print("returned at type")740 return "-1"741 if like == 0:742 like = -1743 elif like == 1:744 pass745 else:746 print("returned at like")747 return "-1"748 cursor = execute_sql("select null from actions where value1 = %s and value2 = %s and type = %s", [accountID, itemID, action_type])749 if cursor.rowcount == 0:750 cursor = execute_sql("update " + table + " set likes = likes + %s where id = %s", [like, itemID])751 cursor = execute_sql("insert into actions (type,value1,value2) values (%s,%s,%s)", [action_type, accountID, itemID])752 else:753 return "-1"754 return "1"755@app.route(f"{flask_path}/database/accounts/backupGJAccountNew.php", methods=["POST"])756async def saveAccount():757 userName = request.values.get("userName")758 password = request.values.get("password")759 saveData = request.values.get("saveData")760 cursor = execute_sql("select password from accounts where name = %s", [userName])761 if cursor.rowcount == 0 or cursor.rowcount > 1: return "-1"762 encrypted_password = cursor.fetchall()[0][0]763 cipher_suite = Fernet(encryption_key)764 decrypted_password = cipher_suite.decrypt(encrypted_password.encode()).decode()765 if password != decrypted_password: return "-1"766 cursor = execute_sql("update accounts set save_data = %s where name = %s", [saveData, userName])767 return "1"768@app.route(f"{flask_path}/database/accounts/syncGJAccountNew.php", methods=["POST"])769async def loadAccount():770 userName = request.values.get("userName")771 password = request.values.get("password")772 cursor = execute_sql("select password,save_data from accounts where name = %s", [userName])773 if cursor.rowcount == 0 or cursor.rowcount > 1: return "-1"774 user_infos = cursor.fetchall()[0]775 encrypted_password = user_infos[0]776 user_data = user_infos[1]777 cipher_suite = Fernet(encryption_key)778 decrypted_password = cipher_suite.decrypt(encrypted_password.encode()).decode()779 if password != decrypted_password: return "-1"780 return f"{user_data};21;30;a;a"781@app.route(f"{flask_path}/getAccountURL.php", methods=["POST"])782async def getAccountUrl():783 return request.url.replace("/getAccountURL.php", "")784@app.route(f"{flask_path}/rateGJDemon21.php", methods=["POST"])785async def demonRate():786 accountID = request.values.get("accountID")787 gjp = request.values.get("gjp")788 levelID = request.values.get("levelID")789 rating = request.values.get("rating")790 gjp_check = check_gjp(accountID, gjp)791 if not gjp_check:792 return "-1"793 image = None794 if rating == "1":795 rating = "3"796 image = "demon-easy"797 elif rating == "2":798 rating = "4"799 image = "demon-medium"800 elif rating == "3":801 rating = "0"802 image = "demon-hard"803 elif rating == "4":804 rating = "5"805 image = "demon-insane"806 elif rating == "5":807 rating = "6"808 image = "demon-extreme"809 else:810 return "-1"811 812 demon_rate_name = get_demon_rate_name(rating, "real")813 cursor = execute_sql("select role from accounts where id = %s", [accountID])814 role_id = cursor.fetchall()[0][0]815 if role_id != 9999:816 cursor = execute_sql("select perm_rate from roles where id = %s", [role_id])817 perm = cursor.fetchall()[0][0]818 if perm == 1:819 cursor = execute_sql("select featured,demon_difficulty,name,author_id from levels where id = %s", [levelID])820 result = cursor.fetchall()[0]821 cursor = execute_sql("select name from accounts where id = %s", [result[3]])822 author_name = cursor.fetchall()[0][0]823 old_demon_rate_name = get_demon_rate_name(result[1], "real")824 if result[0] == 1:825 image = f"{image}-featured"826 cursor = execute_sql("update levels set demon_difficulty = %s where id = %s", [rating, levelID])827 data = {"embeds": [{"title": "A level got its demon rating updated!",828 "description" : f"<:play:900086729120292974> **{result[2]}** by {author_name} \n<:demonupdate:902531596744273970> {old_demon_rate_name} > {demon_rate_name} \nð {levelID}",829 "color": 16733440,830 "thumbnail": {"url": f"https://mathieuar.fr/gdps_assets/{image}.png"}}]}831 requests.post(rate_update_webhook, json = data)832 else:833 cursor = execute_sql("select null from actions where type = 'demon_suggestion' and value1 = %s", [accountID])834 if cursor.rowcount == 0:835 cursor = execute_sql("insert into actions (type,value1,value2) values ('demon_suggestion',%s,%s)", [accountID, rating])836 else:837 cursor = execute_sql("update actions set value2 = %s where type = 'demon_suggestion' and value1 = %s", [rating, accountID])838 return str(levelID)839@app.route(f"{flask_path}/getGJGauntlets21.php", methods=["POST"])840async def getGauntlets():841 cursor = execute_sql("select id,lvl1,lvl2,lvl3,lvl4,lvl5 from gauntlets order by id asc")842 if cursor.rowcount == 0: return "0"843 all_gauntlets = cursor.fetchall()844 gauntlet_string = ""845 gauntlet_string2 = ""846 for gauntlet in all_gauntlets:847 lvl = f"{gauntlet[1]},{gauntlet[2]},{gauntlet[3]},{gauntlet[4]},{gauntlet[5]}"848 gauntlet_string = f"{gauntlet_string}1:{gauntlet[0]}:3:{lvl}|"849 gauntlet_string2 = f"{gauntlet_string2}{gauntlet[0]}{lvl}"850 hashed_string = sha1(f"{gauntlet_string2}xI25fpAapCQg".encode()).hexdigest()851 return f"{gauntlet_string}#{hashed_string}"852@app.route(f"{flask_path}/uploadGJMessage20.php", methods=["POST"])853async def sendPrivateMessage():854 accountID = request.values.get("accountID")855 gjp = request.values.get("gjp")856 toAccountID = request.values.get("toAccountID")857 subject = request.values.get("subject")858 body = request.values.get("body")859 gjp_check = check_gjp(accountID, gjp)860 if not gjp_check:861 return "-1"862 cursor = execute_sql("select privatemsg_status from accounts where id = %s", [toAccountID])863 message_status = cursor.fetchall()[0][0]864 is_friend = False865 if message_status == 1:866 cursor = execute_sql("select null from friends where friend1 = %s and friend2 = %s or friend1 = %s and friend2 = %s", [accountID, toAccountID, toAccountID, accountID])867 if cursor.rowcount > 0:868 is_friend = True869 cursor = execute_sql("select null from blocked where user_id = %s and blocked_user_id = %s", [toAccountID, accountID])870 if cursor.rowcount > 0 or message_status == 2 or is_friend is False:871 return "-1"872 cursor = execute_sql("insert into private_messages (from_id,to_id,subject,body,sent_on) values (%s,%s,%s,%s,%s)", [accountID, toAccountID, subject, body, int(time.time())])873 return "1"874@app.route(f"{flask_path}/getGJMessages20.php", methods=["POST"])875async def getPrivateMessage():876 accountID = request.values.get("accountID")877 gjp = request.values.get("gjp")878 getSent = request.values.get("getSent")879 page = int(request.values.get("page"))*10880 print(request.values)881 gjp_check = check_gjp(accountID, gjp)882 if not gjp_check:883 return "-1"884 msg_count = 0885 if getSent is None or getSent == "":886 cursor = execute_sql("select null from private_messages where to_id = %s", [accountID])887 msg_count = cursor.rowcount888 cursor = execute_sql("select id,from_id,subject,sent_on,is_new from private_messages where to_id = %s order by sent_on desc limit 10 offset %s", [accountID, page])889 getSent = 0890 else:891 cursor = execute_sql("select null from private_messages where from_id = %s", [accountID])892 msg_count = cursor.rowcount893 cursor = execute_sql("select id,to_id,subject,sent_on,is_new from private_messages where from_id = %s order by sent_on desc limit 10 offset %s", [accountID, page])894 getSent = 1895 if msg_count == 0: return "-2"896 messages = cursor.fetchall()897 msg_string = ""898 for msg in messages:899 cursor = execute_sql("select name from accounts where id = %s", [msg[1]])900 user_name = cursor.fetchall()[0][0]901 is_new = msg[4]902 if is_new == 1:903 is_new = 0904 else:905 is_new = 1906 msg_string = f"{msg_string}6:{user_name}:3:{msg[1]}:2:{msg[1]}:1:{msg[0]}:4:{msg[2]}:8:{is_new}:9:{getSent}:7:{msg[3]}|"907 return f"{msg_string}#{msg_count}:{page}:10"908@app.route(f"{flask_path}/downloadGJMessage20.php", methods=["POST"])909async def downloadPrivateMessage():910 accountID = request.values.get("accountID")911 gjp = request.values.get("gjp")912 messageID = request.values.get("messageID")913 isSender = request.values.get("isSender")914 gjp_check = check_gjp(accountID, gjp)915 if not gjp_check:916 return "-1"917 message = ""918 if isSender is None or isSender == "":919 cursor = execute_sql("select from_id,sent_on,subject,is_new,body from private_messages where id = %s and to_id = %s", [messageID, accountID])920 if cursor.rowcount == 0: return "-1"921 message = cursor.fetchall()[0]922 cursor = execute_sql("update private_messages set is_new = 0 where id = %s and to_id = %s", [messageID, accountID])923 isSender = 0924 else:925 cursor = execute_sql("select to_id,sent_on,subject,is_new,body from private_messages where id = %s and from_id = %s", [messageID, accountID])926 if cursor.rowcount == 0: return "-1"927 message = cursor.fetchall()[0]928 isSender = 1929 cursor = execute_sql("select name from accounts where id = %s", [message[0]])930 user_name = cursor.fetchall()[0][0]931 return f"6:{user_name}:3:{message[0]}:2:{message[0]}:1:{messageID}:4:{message[2]}:8:{message[3]}:9:{isSender}:5:{message[4]}:7:{message[1]}"932@app.route(f"{flask_path}/blockGJUser20.php", methods=["POST"])933async def blockUser():934 accountID = request.values.get("accountID")935 gjp = request.values.get("gjp")936 targetAccountID = request.values.get("targetAccountID")937 gjp_check = check_gjp(accountID, gjp)938 if not gjp_check:939 return "-1"940 cursor = execute_sql("insert into blocked (user_id,blocked_user_id) values (%s,%s)", [accountID, targetAccountID])941 return "1"942@app.route(f"{flask_path}/getGJUserList20.php", methods=["POST"])943async def getUserList():944 accountID = request.values.get("accountID")945 gjp = request.values.get("gjp")946 gd_type = request.values.get("type")947 gjp_check = check_gjp(accountID, gjp)948 user_list = None949 if not gjp_check:950 return "-1"951 if gd_type == "0":952 cursor = execute_sql("select friend1,friend2,is_new1,is_new2 from friends where friend1 = %s or friend2 = %s", [accountID, accountID])953 if cursor.rowcount == 0:954 return "-2"955 user_list = cursor.fetchall()956 elif gd_type == "1":957 cursor = execute_sql("select blocked_user_id from blocked where user_id = %s", [accountID])958 if cursor.rowcount == 0:959 return "-2"960 user_list = cursor.fetchall()961 else:962 return "-1"963 peoplestring = ""964 for user in user_list:965 if gd_type == "1":966 cursor = execute_sql("select name,icon,color1,color2,icon_type,special from accounts where id = %s", [user[0]])967 user_infos = cursor.fetchall()[0]968 peoplestring = f"{peoplestring}1:{user_infos[0]}:2:{user[0]}:9:{user_infos[1]}:10:{user_infos[2]}:11:{user_infos[3]}:14:{user_infos[4]}:15:{user_infos[5]}:16:{user[0]}:18:0:41:0"969 else:970 user_id = user[0]971 is_new = user[3]972 if accountID == str(user[0]):973 user_id = user[1]974 is_new = user[2]975 cursor = execute_sql("select name,icon,color1,color2,icon_type,special from accounts where id = %s", [user_id])976 user_infos = cursor.fetchall()[0]977 peoplestring = f"{peoplestring}1:{user_infos[0]}:2:{user_id}:9:{user_infos[1]}:10:{user_infos[2]}:11:{user_infos[3]}:14:{user_infos[4]}:15:{user_infos[5]}:16:{user_id}:18:0:41:{is_new}|"978 cursor = execute_sql("update friends set is_new1 = 0 where friend1 = %s", [accountID])979 cursor = execute_sql("update friends set is_new2 = 0 where friend2 = %s", [accountID])980 return peoplestring981@app.route(f"{flask_path}/uploadFriendRequest20.php", methods=["POST"])982async def sendFriendRequest():983 accountID = request.values.get("accountID")984 gjp = request.values.get("gjp")985 toAccountID = request.values.get("toAccountID")986 comment = request.values.get("comment")987 gjp_check = check_gjp(accountID, gjp)988 if not gjp_check:989 return "-1"990 cursor = execute_sql("select friendsreq_status from accounts where id = %s", [toAccountID])991 friendreq_status = cursor.fetchall()[0][0]992 cursor = execute_sql("select null from blocked where user_id = %s and blocked_user_id = %s", [toAccountID, accountID])993 if cursor.rowcount > 0 or friendreq_status == 1: return "-1"994 cursor = execute_sql("select null from friend_requests where user_id = %s and req_user_id = %s", [accountID, toAccountID])995 if cursor.rowcount > 0: return "-1"996 cursor = execute_sql("insert into friend_requests (user_id,req_user_id,comment,requested_on) values (%s,%s,%s,%s)", [accountID, toAccountID, comment, int(time.time())])997 return "1"998@app.route(f"{flask_path}/getGJFriendRequests20.php", methods=["POST"])999async def getFriendRequests():1000 accountID = request.values.get("accountID")1001 gjp = request.values.get("gjp")1002 getSent = request.values.get("getSent")1003 page = int(request.values.get("page"))*101004 gjp_check = check_gjp(accountID, gjp)1005 if not gjp_check:1006 return "-1"1007 req_count = 01008 if getSent is None or getSent == "":1009 cursor = execute_sql("select null from friend_requests where req_user_id = %s", [accountID])1010 req_count = cursor.rowcount1011 cursor = execute_sql("select id,user_id,comment,requested_on,is_new from friend_requests where req_user_id = %s order by requested_on desc limit 10 offset %s", [accountID, page])1012 getSent = 01013 else:1014 cursor = execute_sql("select null from friend_requests where user_id = %s", [accountID])1015 req_count = cursor.rowcount1016 cursor = execute_sql("select id,req_user_id,comment,requested_on,is_new from friend_requests where user_id = %s order by requested_on desc limit 10 offset %s", [accountID, page])1017 getSent = 11018 if req_count == 0: return "-2"1019 friend_requests = cursor.fetchall()1020 friend_string = ""1021 for req in friend_requests:1022 cursor = execute_sql("select name,icon,color1,color2,icon_type,special from accounts where id = %s", [req[1]])1023 user_infos = cursor.fetchall()[0]1024 is_new = req[4]1025 if is_new == 1:1026 is_new = 01027 else:1028 is_new = 11029 friend_string = f"{friend_string}1:{user_infos[0]}:2:{req[1]}:9:{user_infos[1]}:10:{user_infos[2]}:11:{user_infos[3]}:14:{user_infos[4]}:15:{user_infos[5]}:16:{req[1]}:32:{req[0]}:35:{req[2]}:41:{req[4]}:37:{req[3]}|"1030 if getSent == 0:1031 cursor = execute_sql("update friend_requests set is_new = 0 where user_id = %s and req_user_id = %s", [req[1], accountID])1032 return f"{friend_string}#{req_count}:{page}:10"1033@app.route(f"{flask_path}/acceptGJFriendRequest20.php", methods=["POST"])1034async def acceptFriendRequest():1035 accountID = request.values.get("accountID")1036 gjp = request.values.get("gjp")1037 targetAccountID = request.values.get("targetAccountID")1038 requestID = request.values.get("requestID")1039 gjp_check = check_gjp(accountID, gjp)1040 if not gjp_check:1041 return "-1"1042 cursor = execute_sql("select null from friend_requests where id = %s and user_id = %s and req_user_id = %s", [requestID, targetAccountID, accountID])1043 if cursor.rowcount == 0: return "-1"1044 cursor = execute_sql("select null from friends where friend1 = %s and friend2 = %s or friend1 = %s and friend2 = %s", [accountID, targetAccountID, targetAccountID, accountID])1045 if cursor.rowcount == 0:1046 cursor = execute_sql("insert into friends (friend1,friend2) values (%s,%s)", [accountID, targetAccountID])1047 cursor = execute_sql("delete from friend_requests where id = %s", [requestID])1048 return "1"1049@app.route(f"{flask_path}/deleteGJFriendRequests20.php", methods=["POST"])1050async def deleteFriendRequest():1051 accountID = request.values.get("accountID")1052 gjp = request.values.get("gjp")1053 targetAccountID = request.values.get("targetAccountID")1054 isSender = int(request.values.get("isSender"))1055 gjp_check = check_gjp(accountID, gjp)1056 if not gjp_check:1057 return "-1"1058 if isSender == 1:1059 cursor = execute_sql("delete from friend_requests where user_id = %s and req_user_id = %s", [accountID, targetAccountID])1060 else:1061 cursor = execute_sql("delete from friend_requests where user_id = %s and req_user_id = %s", [targetAccountID, accountID])1062 return "1"1063@app.route(f"{flask_path}/removeGJFriend20.php", methods=["POST"])1064async def removeFriend():1065 accountID = request.values.get("accountID")1066 gjp = request.values.get("gjp")1067 targetAccountID = request.values.get("targetAccountID")1068 gjp_check = check_gjp(accountID, gjp)1069 if not gjp_check:1070 return "-1"1071 print(request.values)1072 cursor = execute_sql("delete from friends where friend1 = %s and friend2 = %s or friend1 = %s and friend2 = %s", [accountID, targetAccountID, targetAccountID, accountID])1073 return "1"1074@app.route(f"{flask_path}/getGJRewards.php", methods=["POST"])1075async def getChestReward():1076 accountID = request.values.get("accountID")1077 gjp = request.values.get("gjp")1078 rewardType = request.values.get("rewardType")1079 chk = request.values.get("chk")1080 udid = request.values.get("udid")1081 gjp_check = check_gjp(accountID, gjp)1082 if not gjp_check:1083 return "-1"1084 chk = xor_cipher(b64_decode(chk[5:]), "59182")1085 cursor = execute_sql("select chest_s_time, chest_b_time, chest_s_count, chest_b_count from accounts where id = %s", [accountID])1086 chests_infos = cursor.fetchall()[0]1087 small_chest_time = chests_infos[0]1088 big_chest_time = chests_infos[1]1089 small_chest_count = chests_infos[2]1090 big_chest_count = chests_infos[3]1091 current_time = int(time.time())1092 small_chest_wait = 36001093 big_chest_wait = 144001094 small_chest_str = f"{random.randint(200, 400)},{random.randint(2, 10)},{random.randint(1, 6)},{random.randint(1, 6)}"1095 big_chest_str = f"{random.randint(2000, 4000)},{random.randint(20, 100)},{random.randint(1, 6)},{random.randint(1, 6)}"1096 small_chest_time_left = small_chest_time - current_time1097 big_chest_time_left = big_chest_time - current_time1098 match rewardType:1099 case "1":1100 if small_chest_time > current_time:1101 return "-1"1102 small_chest_count += 11103 small_chest_time_left = small_chest_wait1104 cursor = execute_sql("update accounts set chest_s_count = chest_s_count + 1, chest_s_time = %s where id = %s", [current_time + small_chest_wait, accountID])1105 case "2":1106 if big_chest_time > current_time:1107 return "-1"1108 big_chest_count += 11109 big_chest_time_left = big_chest_wait1110 cursor = execute_sql("update accounts set chest_b_count = chest_b_count + 1, chest_b_time = %s where id = %s", [current_time + big_chest_wait, accountID])1111 if small_chest_time_left < 0:1112 small_chest_time_left = 01113 if big_chest_time_left < 0:1114 big_chest_time_left = 01115 chest_response = b64_encode(xor_cipher(f"1:{accountID}:{chk}:{udid}:{accountID}:{abs(small_chest_time_left)}:{small_chest_str}:{small_chest_count}:{abs(big_chest_time_left)}:{big_chest_str}:{big_chest_count}:{rewardType}", "59182")).replace("/", "_").replace("+", "-")1116 response_hash = chest_response + "pC26fpYaQCtg"1117 response_hash = sha1(response_hash.encode()).hexdigest()1118 return f"SaKuJ{chest_response}|{response_hash}"1119@app.route(f"{flask_path}/getGJMapPacks21.php", methods=["POST"])1120async def getMapPacks():1121 page = request.values.get("page")1122 page = int(page)*101123 cursor = execute_sql("select id,name,levels,stars,coins,difficulty,color from map_packs order by id asc limit 10 offset %s", [page])1124 if cursor.rowcount == 0: return "-1"1125 pack_data = cursor.fetchall()1126 pack_str = ""1127 pack_ids = []1128 for pack in pack_data:1129 pack_ids.append(pack[0])1130 pack_str = f"{pack_str}1:{pack[0]}:2:{pack[1]}:3:{pack[2]}:4:{pack[3]}:5:{pack[4]}:6:{pack[5]}:7:{pack[6]}:8:{pack[6]}|"1131 cursor = execute_sql("select null from map_packs")1132 pack_count = cursor.rowcount1133 pack_str = pack_str[:-1]1134 pack_lvl_hash = get_mappacks_hash(pack_ids)1135 response = f"{pack_str}#{pack_count}:{page}:10#{pack_lvl_hash}"1136 return response1137@app.route(f"{flask_path}/getGJChallenges.php", methods=["POST"])1138async def getQuests():1139 accountID = request.values.get("accountID")1140 gjp = request.values.get("gjp")1141 udid = request.values.get("udid")1142 chk = request.values.get("chk")1143 chk = xor_cipher(b64_decode(chk[5:]), "19847")1144 gjp_check = check_gjp(accountID, gjp)1145 if not gjp_check:1146 return "-1"1147 cursor = execute_sql("select id,name,type,amount,reward from quests")1148 if cursor.rowcount < 3:1149 return "-1"1150 quests = cursor.fetchall()1151 quest1 = random.choice(quests)1152 quests.remove(quest1)1153 quest2 = random.choice(quests)1154 quests.remove(quest2)1155 quest3 = random.choice(quests)1156 quest1_resp = f"{quest1[0]},{quest1[2]},{quest1[3]},{quest1[4]},{quest1[1]}"1157 quest2_resp = f"{quest2[0]},{quest2[2]},{quest2[3]},{quest2[4]},{quest2[1]}"1158 quest3_resp = f"{quest3[0]},{quest3[2]},{quest3[3]},{quest3[4]},{quest3[1]}"1159 current_time = int(time.time())1160 next_midnight = ((current_time//86400)+1)*864001161 response = b64_encode(xor_cipher(f"SaKuJ:{accountID}:{chk}:{udid}:{accountID}:{next_midnight-current_time}:{quest1_resp}:{quest2_resp}:{quest3_resp}", "19847"))1162 hashed = sha1((response + "oC36fpYaPtdg").encode()).hexdigest()1163 return f"SaKuJ{response}|{hashed}"1164@app.route("/test", methods=["POST", "GET"])1165async def test():1166 return "k"1167def get_demon_rate_name(rate_id, type = None):1168 rate_id = int(rate_id)1169 demon_name = "Unknown"1170 if type == "real":1171 if rate_id == 3:1172 demon_name = "Easy"1173 elif rate_id == 4:1174 demon_name = "Medium"1175 elif rate_id == 0:1176 demon_name = "Hard"1177 elif rate_id == 5:1178 demon_name = "Insane"1179 elif rate_id == 6:1180 demon_name = "Extreme"1181 else:1182 if rate_id == 1:1183 demon_name = "Easy"1184 elif rate_id == 2:1185 demon_name = "Medium"1186 elif rate_id == 3:1187 demon_name = "Hard"1188 elif rate_id == 4:1189 demon_name = "Insane"1190 elif rate_id == 5:1191 demon_name = "Extreme"1192 return demon_name1193def start_cron():1194 while True:1195 print("Started cron")1196 cursor = execute_sql("select verified,id,created_on from accounts")1197 all_users = cursor.fetchall()1198 for user in all_users:1199 is_verified = user[0]1200 user_id = user[1]1201 created_on = user[2]1202 # Delete account if its not verified after 15 minutes1203 if is_verified == 0:1204 current_timestamp = int(time.time())1205 if created_on+900 < current_timestamp:1206 cursor = execute_sql("select ip from accounts where id = %s", [user_id])1207 ip = cursor.fetchall()[0][0]1208 cursor = execute_sql("delete from accounts where id = %s", [user_id])1209 if ip != "127.0.0.1":1210 cursor = execute_sql("delete from register_ips where ip = %s", [ip])1211 continue1212 # Set creator points of all users1213 cursor = execute_sql("select stars,featured,epic from levels where author_id = %s", [user_id])1214 all_levels = cursor.fetchall()1215 cp = 01216 for level in all_levels:1217 if level[0] > 0:1218 cp += 11219 if level[1] == 1:1220 cp += 11221 if level[2] > 0:1222 cp += 11223 cursor = execute_sql("update accounts set creator_points = %s where id = %s", [cp, user_id])1224 print("Finished cron")1225 time.sleep(300)1226def xor_cipher(string: str, key: str) -> str:1227 return ("").join(chr(ord(x) ^ ord(y)) for x, y in zip(string, itertools.cycle(key)))1228def b64_encode(string):1229 string = string.encode("ascii")1230 return base64.b64encode(string).decode()1231def b64_decode(string):1232 string = string.encode("ascii")1233 return base64.b64decode(string).decode()1234def get_gjp(password):1235 password = xor_cipher(password, "37526")1236 password = b64_encode(password)1237 return str(password).replace("/", "_").replace("+", "-")1238def check_gjp(user_id, given_gjp):1239 cursor = execute_sql("select password from accounts where id = %s and verified = 1", [user_id])1240 if cursor.rowcount == 0:1241 return False1242 encrypted_password = cursor.fetchall()[0][0]1243 cipher_suite = Fernet(encryption_key)1244 decrypted_password = cipher_suite.decrypt(encrypted_password.encode()).decode()1245 gjp = get_gjp(decrypted_password)1246 if gjp != given_gjp:1247 return False1248 else:1249 return True1250def get_user_name(id):1251 cursor = execute_sql("select name from accounts where id = %s", [id])1252 if cursor.rowcount > 0:1253 name = cursor.fetchall()[0][0]1254 else:1255 name = None1256 return name1257def get_levels_hash(lvl_list):1258 hash = ""1259 for id in lvl_list:1260 cursor = execute_sql("SELECT id, stars, coins_verified FROM levels WHERE id = %s", [id])1261 level = cursor.fetchall()[0]1262 hash = f"{hash}{str(level[0])[0]}{str(level[0])[len(str(level[0]))-1]}{str(level[1])}{str(level[2])}"1263 hash = hash + "xI25fpAapCQg"1264 encoded = sha1(hash.encode())1265 return encoded.hexdigest()1266def get_encode_song(song_id):1267 cursor = execute_sql("SELECT id,name,author_id,author_name,size,download_link FROM songs WHERE id = %s LIMIT 1", [song_id])1268 if cursor.rowcount == 0:1269 headers = {"Content-type": "application/x-www-form-urlencoded",1270 "User-Agent": ""}1271 data = {"songID": song_id,1272 "secret": "Wmfd2893gb7"}1273 req = requests.post("http://www.boomlings.com/database/getGJSongInfo.php", data=data, headers=headers)1274 response = req.text1275 if response == "-2":1276 return response1277 elif response == "-1":1278 return response1279 resp = response.replace("~", "").split("|")1280 cursor = execute_sql("insert into songs (id,name,author_id,author_name,size,download_link) values (%s,%s,%s,%s,%s,%s)", [resp[1], resp[3], resp[5], resp[7], resp[9], resp[13]])1281 return req.text1282 elif cursor.rowcount == 1:1283 song_info = cursor.fetchall()[0]1284 song_name = song_info[1].replace("#", "")1285 return f"1~|~{song_info[0]}~|~2~|~{song_name}~|~3~|~{song_info[2]}~|~4~|~{song_info[3]}~|~5~|~{song_info[4]}~|~6~|~~|~10~|~{song_info[5]}~|~7~|~~|~8~|~1"1286def get_encoded_lvlstring(lvlstring):1287 lvl_hash = []1288 length = len(lvlstring)1289 divided = int(length/40)1290 count = 01291 kcount = 01292 first_loop = False1293 while True:1294 if kcount < length:1295 if first_loop == True:1296 kcount = kcount+divided1297 if count > 39:1298 break1299 lvl_hash.append(lvlstring[kcount])1300 count += 11301 else:1302 break1303 first_loop = True1304 lvl_hash = "".join(lvl_hash)1305 print(lvl_hash)1306 lvl_hash = lvl_hash + "xI25fpAapCQg"1307 encoded = sha1(lvl_hash.encode())1308 return encoded.hexdigest()1309def get_mappacks_hash(lvl_list):1310 hash = ""1311 for lvl_id in lvl_list:1312 cursor = execute_sql("select id,stars,coins from map_packs where id = %s", [lvl_id])1313 pack_info = cursor.fetchall()[0]1314 hash = f"{hash}{str(pack_info[0])[0]}{str(pack_info[0])[len(str(pack_info[0]))-1]}{pack_info[1]}{pack_info[2]}"1315 hash = hash + "xI25fpAapCQg"1316 return sha1(hash.encode()).hexdigest()1317def send_mail(send_to, content):1318 message = MIMEMultipart("alternative")1319 message["Subject"] = "Account verification"1320 message["From"] = f"Ultimate GDPS <{mail_email}>"1321 message["To"] = send_to1322 message["Date"] = formatdate(localtime=True)1323 part1 = MIMEText(content, "html")1324 message.attach(part1)1325 smtpObj = smtplib.SMTP(mail_smtp_server, mail_port)1326 smtpObj.starttls()1327 smtpObj.login(mail_email, mail_password)1328 smtpObj.sendmail(mail_email, send_to, message.as_string()) 1329def generate_token():1330 characters = list(string.ascii_letters + string.digits)1331 random.shuffle(characters)1332 password = []1333 for i in range(60):1334 password.append(random.choice(characters))1335 random.shuffle(password)1336 return "".join(password)1337def execute_sql(command, values=None):1338 global cursor1339 try:1340 cursor.execute(command, values)1341 except Exception as e:1342 print(e)1343 global connection1344 connection.disconnect()1345 count = 01346 while True:1347 connection = mysql.connector.connect(host=mysql_ip,1348 database=mysql_database,1349 user=mysql_user,1350 port = int(mysql_port),1351 password=mysql_pass)...
test_module3.py
Source:test_module3.py
...60 assert 'close' in get_functions(app.execute_sql), 'Have you called the `close` function in `execute_sql`?'61 assert len(get_statements(app.execute_sql)) >= 0, 'Have created an if statement in the `execute_sql` function?'62 assert 'results' == get_statements(app.execute_sql)[0]['body/targets/id'], 'Have you assigned the `results` variable to `connection.commit()`?'63 with app.app.app_context():64 results = app.execute_sql('SELECT * FROM job', single=True)65 assert type(results) != list, 'Have you create an if statement to only return one result in `one` is true?'66@pytest.mark.test_app_close_connection_module367def test_app_close_connection_module3():68 assert 'close_connection' in dir(app), 'Have you defined a function named `close_connection`.'69 assert 'getattr:g:_connection:None' in get_functions(app.open_connection), 'Have you used the `getattr` function to get the global `_connection`?'70 assert 'close' in get_functions(app.execute_sql), 'Have you called the `close` function in `execute_sql`?'71@pytest.mark.test_app_close_connection_decorator_module372def test_app_close_connection_decorator_module3():73 assert 'close_connection' in dir(app), 'Have you defined a function named `close_connection`.'74 decorators = get_decorators(app.close_connection)['close_connection']75 assert len(decorators) == 1, 'Have you added the correct decorator to `close_connection`.'76 decorator = decorators[0][0]...
psql_procedures.py
Source:psql_procedures.py
...7# ETL8################################################################9def load_tweet_contributions():10 tsql = f"""call sp_load_tweet_contributions();"""11 psql.execute_sql(tsql)12# DROP STAGE TABLES 13def drop_stage_contributions():14 tsql = f"""drop table stage_contributions"""15 psql.execute_sql(tsql) 16def drop_stage_expenditures():17 tsql = f"""drop table stage_expenditures"""18 psql.execute_sql(tsql) 19 20# TRUNCATE STAGE TABLES 21def truncate_stage_contributions():22 tsql = f"""truncate table stage_contributions"""23 psql.execute_sql(tsql) 24def truncate_stage_expenditures():25 tsql = f"""truncate table stage_expenditures"""26 psql.execute_sql(tsql) 27 28def truncate_ppp_data():29 tsql = f"""truncate table ppp_data"""30 psql.execute_sql(tsql) 31 32# LOAD TABLES FROM STAGE33def load_contributions():34 tsql = f"""call sp_load_contribution();"""35 psql.execute_sql(tsql)36 37def load_expenditures():38 tsql = f"""call sp_load_expenditure();"""39 psql.execute_sql(tsql) 40 41def load_filers():42 tsql = f"""call sp_load_filer();"""43 psql.execute_sql(tsql)44 45def load_payees():46 tsql = f"""call sp_load_payee();"""47 psql.execute_sql(tsql)48 49def load_payors():50 tsql = f"""call sp_load_payor();"""51 psql.execute_sql(tsql) 52 53 54def update_contribution():55 tsql = f"""call sp_update_contribution();"""56 psql.execute_sql(tsql)57 58def update_expenditure():59 tsql = f"""call sp_update_expenditure();"""60 psql.execute_sql(tsql)61 62def update_filer_type_short(): 63 tsql = f"""call sp_update_filer_type_short();"""64 psql.execute_sql(tsql)65 66 67 68 69 70def main():71 load_filers() 72if __name__ == '__main__':73 main()74 # drop_stage_contributions()75 # drop_stage_expenditures()76 77 78 # update_contribution()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!