From 022e300d2fb00dfb5817402fb3f2f63abf16bbf7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 6 Feb 2022 12:54:05 +0200 Subject: [PATCH] SDF --- files/__main__.py | 2 +- files/classes/blackjack.py | 2 +- files/helpers/sanitize.py | 2 +- files/routes/admin.py | 6 +++--- files/routes/comments.py | 2 +- files/routes/posts.py | 2 +- files/routes/search.py | 4 ++-- files/routes/static.py | 2 +- files/routes/users.py | 8 ++++---- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 89a6f0795..46109b79a 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -19,7 +19,7 @@ from json import loads f = 'files/templates/sidebar_' + environ.get("SITE_NAME").strip() + '.html' if not path.exists(f): - with open(f, 'w'): pass + with open(f, 'w', encoding="utf-8"): pass app = Flask(__name__, template_folder='templates') app.url_map.strict_slashes = False diff --git a/files/classes/blackjack.py b/files/classes/blackjack.py index ffa8d6b58..7bacefdaf 100644 --- a/files/classes/blackjack.py +++ b/files/classes/blackjack.py @@ -41,7 +41,7 @@ def get_hand_value(hand): def format_cards(hand): - return map(lambda x: "".join(x), hand) + return map("".join(x), hand) def format_all(player_hand, dealer_hand, deck, status, wager): diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 700bd720b..499e3c335 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -159,7 +159,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): tag["data-src"] = tag["src"] tag["src"] = "/static/assets/images/loading.webp" tag['alt'] = f'![]({tag["data-src"]})' - tag["onclick"] = f"expandDesktopImage(this.src);" + tag["onclick"] = "expandDesktopImage(this.src);" tag["data-bs-toggle"] = "modal" tag["data-bs-target"] = "#expandImageModal" diff --git a/files/routes/admin.py b/files/routes/admin.py index a0c75a145..c290d8d08 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -314,7 +314,7 @@ def monthly(v): def get_sidebar(v): try: - with open(f'files/templates/sidebar_{SITE_NAME}.html', 'r') as f: sidebar = f.read() + with open(f'files/templates/sidebar_{SITE_NAME}.html', 'r', encoding="utf-8") as f: sidebar = f.read() except: sidebar = None @@ -328,9 +328,9 @@ def post_sidebar(v): text = request.values.get('sidebar', '').strip() - with open(f'files/templates/sidebar_{SITE_NAME}.html', 'w+') as f: f.write(text) + with open(f'files/templates/sidebar_{SITE_NAME}.html', 'w+', encoding="utf-8") as f: f.write(text) - with open(f'files/templates/sidebar_{SITE_NAME}.html', 'r') as f: sidebar = f.read() + with open(f'files/templates/sidebar_{SITE_NAME}.html', 'r', encoding="utf-8") as f: sidebar = f.read() ma = ModAction( kind="change_sidebar", diff --git a/files/routes/comments.py b/files/routes/comments.py index 6019d827d..a3404874c 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -165,7 +165,7 @@ def api_comment(v): body = request.values.get("body", "").strip()[:10000] if v.admin_level == 3 and parent_post.id == 37749: - with open(f"snappy_{SITE_NAME}.txt", "a") as f: + with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f: f.write('\n{[para]}\n' + body) if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838): diff --git a/files/routes/posts.py b/files/routes/posts.py index 4ff965f35..0887e5581 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -24,7 +24,7 @@ marseys = tuple(f':#{x[0]}:' for x in db.query(Marsey.name).all()) db.close() if path.exists(f'snappy_{SITE_NAME}.txt'): - with open(f'snappy_{SITE_NAME}.txt', "r") as f: + with open(f'snappy_{SITE_NAME}.txt', "r", encoding="utf-8") as f: if SITE == 'pcmemes.net': snappyquotes = tuple(f.read().split("{[para]}")) else: snappyquotes = tuple(f.read().split("{[para]}")) + marseys else: snappyquotes = marseys diff --git a/files/routes/search.py b/files/routes/search.py index f4918a40b..b99d19f68 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -66,7 +66,7 @@ def searchposts(v): if 'author' in criteria: posts = posts.filter(Submission.ghost == None) author = get_user(criteria['author']) - if not author: return {"error": f"User not found"} + if not author: return {"error": "User not found"} if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye: if request.headers.get("Authorization"): return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"} @@ -213,7 +213,7 @@ def searchcomments(v): if 'author' in criteria: comments = comments.filter(Comment.ghost == None) author = get_user(criteria['author']) - if not author: return {"error": f"User not found"} + if not author: return {"error": "User not found"} if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye: if request.headers.get("Authorization"): return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"} diff --git a/files/routes/static.py b/files/routes/static.py index 27abf423f..6fc3384c1 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -384,7 +384,7 @@ def formatting(v): @app.get("/service-worker.js") def serviceworker(): - with open("files/assets/js/service-worker.js", "r") as f: return Response(f.read(), mimetype='application/javascript') + with open("files/assets/js/service-worker.js", "r", encoding="utf-8") as f: return Response(f.read(), mimetype='application/javascript') @app.get("/settings/security") @auth_required diff --git a/files/routes/users.py b/files/routes/users.py index c7faa2f33..34d547643 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -256,9 +256,9 @@ def transfer_coins(v, username): amount = request.values.get("amount", "").strip() amount = int(amount) if amount.isdigit() else None - if amount is None or amount <= 0: return {"error": f"Invalid amount of coins."}, 400 - if v.coins < amount: return {"error": f"You don't have enough coins."}, 400 - if amount < 100: return {"error": f"You have to gift at least 100 coins."}, 400 + if amount is None or amount <= 0: return {"error": "Invalid amount of coins."}, 400 + if v.coins < amount: return {"error": "You don't have enough coins."}, 400 + if amount < 100: return {"error": "You have to gift at least 100 coins."}, 400 if not v.patron and not receiver.patron and not v.alts_patron and not receiver.alts_patron: tax = math.ceil(amount*0.03) else: tax = 0 @@ -275,7 +275,7 @@ def transfer_coins(v, username): g.db.commit() return {"message": f"{amount-tax} coins transferred!"}, 200 - return {"message": f"You can't transfer coins to yourself!"}, 400 + return {"message": "You can't transfer coins to yourself!"}, 400 @app.post("/@/transfer_bux")