diff --git a/files/__main__.py b/files/__main__.py index 1d072c9d7..53fbdca7c 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -16,7 +16,6 @@ import time from sys import stdout import faulthandler from json import loads -import atexit app = Flask(__name__, template_folder='templates') app.url_map.strict_slashes = False @@ -116,12 +115,4 @@ def after_request(response): response.headers.add("X-Frame-Options", "deny") return response -if not cache.get("marseys"): - with open("marseys.json", 'r') as f: cache.set("marseys", loads(f.read())) - -from files.routes import * - -def close_running_threads(): - with open('marseys.json', 'w') as f: dump(cache.get("marseys"), f) - stdout.flush() -atexit.register(close_running_threads) \ No newline at end of file +from files.routes import * \ No newline at end of file diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 7cc170a42..fffaf4432 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -178,7 +178,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = re.sub('\|\|(.*?)\|\|', r'\1', sanitized) if comment: - marsey_count = cache.get("marseys") + with open("marseys.json", 'r') as f: marsey_count = loads(f.read().replace("'",'"')) marseys_used = set() emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized)) @@ -263,7 +263,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: for emoji in marseys_used: if emoji in marsey_count: marsey_count[emoji]["count"] += 1 - cache.set("marseys", marsey_count) + with open('marseys.json', 'w') as f: dump(marsey_count, f) return sanitized diff --git a/files/routes/comments.py b/files/routes/comments.py index 0cc25cf01..0eb152106 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -172,7 +172,7 @@ def api_comment(v): marsey_body = marsey_dict[0][1] marsey_body["count"] = 0 except: return {"error": "You didn't follow the format retard"}, 400 - marseys = cache.get("marseys") + with open("marseys.json", 'r') as f: marseys = loads(f.read().replace("'",'"')) marseys[marsey_key] = marsey_body if v.marseyawarded: @@ -212,7 +212,7 @@ def api_comment(v): elif v.id in (CARP_ID,AEVANN_ID) and parent_post.id == 37838: filename = f'files/assets/images/emojis/{marsey_key}.webp' process_image(file, filename, 200) - cache.set("marseys", marseys) + with open('marseys.json', 'w') as f: dump(marseys, f) elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: diff --git a/files/routes/posts.py b/files/routes/posts.py index 316644358..370528992 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1008,7 +1008,7 @@ def submit_post(v): with open(f'snappy_{SITE_NAME}.txt', "r") as f: snappyquotes = f.read().split("{[para]}") if request.host != 'pcmemes.net': - marseys = cache.get("marseys").keys() + with open("marseys.json", 'r') as f: marseys = loads(f.read().replace("'",'"')).keys() snappyquotes += [f':#{x}:' for x in marseys] body = random.choice(snappyquotes) body += "\n\n" diff --git a/files/routes/static.py b/files/routes/static.py index 7daa118b9..36d0a6e13 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -17,7 +17,7 @@ def privacy(v): @app.get("/marseys") @auth_required def marseys(v): - marsey_count = cache.get("marseys").items() + with open("marseys.json", 'r') as f: marsey_count = list(loads(f.read().replace("'",'"')).items()) marsey_count = sorted(marsey_count, key=lambda x: list(x[1].values())[2], reverse=True) return render_template("marseys.html", v=v, marseys=marsey_count) @@ -48,7 +48,7 @@ def participation_stats(v): day = now - 86400 - marseys = cache.get("marseys") + with open("marseys.json", 'r') as f: marseys = loads(f.read().replace("'",'"')) data = {"marseys": len(marseys), "users": g.db.query(User.id).count(), @@ -373,7 +373,7 @@ def badges(v): @app.get("/marsey_list") @auth_required def marsey_list(v): - return cache.get("marseys") + with open("marseys.json", 'r') as f: return loads(f.read().replace("'",'"')) @app.get("/blocks") @auth_required diff --git a/files/routes/users.py b/files/routes/users.py index a92ed32b9..037afdf78 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -31,7 +31,7 @@ def leaderboard_thread(): if SITE_NAME == 'Drama': users13 = {} - authors = (x for x in cache.get("marseys").values()) + with open("marseys.json", 'r') as f: authors = (x for x in loads(f.read().replace("'",'"')).values()) for x in authors: if x["author"] in users13: users13[x["author"]] += 1 else: users13[x["author"]] = 1