remotes/1693045480750635534/spooky-22
Aevann1 2022-01-22 21:49:12 +02:00
parent 25e7150c86
commit 65daa0d82c
7 changed files with 23 additions and 14 deletions

View File

@ -16,6 +16,7 @@ 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
@ -50,8 +51,8 @@ app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(environ.get("COMMENT_SPAM_S
app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD", 10))
app.config["READ_ONLY"]=bool(int(environ.get("READ_ONLY", "0")))
app.config["BOT_DISABLE"]=bool(int(environ.get("BOT_DISABLE", False)))
app.config["CACHE_TYPE"] = "filesystem"
app.config["CACHE_DIR"] = "cache"
app.config["CACHE_TYPE"] = "RedisCache"
app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL", "redis://localhost")
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
@ -115,4 +116,12 @@ def after_request(response):
response.headers.add("X-Frame-Options", "deny")
return response
from files.routes import *
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('marsey_count.json', 'w') as f: dump(cache.get("marseys"), f)
stdout.flush()
atexit.register(close_running_threads)

View File

@ -178,7 +178,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
sanitized = re.sub('\|\|(.*?)\|\|', r'<span class="spoiler">\1</span>', sanitized)
if comment:
with open("marseys.json", 'r') as f: marsey_count = loads(f.read().replace("'",'"'))
marsey_count = cache.get("marseys")
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
with open('marseys.json', 'w') as f: dump(marsey_count, f)
marsey_count = cache.set("marseys", marsey_count)
return sanitized

View File

@ -1217,7 +1217,7 @@ def admin_distinguish_comment(c_id, v):
@app.get("/admin/dump_cache")
@admin_level_required(2)
def admin_dump_cache(v):
cache.clear()
# cache.clear()
return {"message": "Internal cache cleared."}

View File

@ -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
with open("marseys.json", 'r') as f: marseys = loads(f.read().replace("'",'"'))
marseys = cache.get("marseys")
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)
with open('marseys.json', 'w') as f: dump(marseys, f)
cache.set("marseys", marseys)
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
@ -860,4 +860,4 @@ def unsave_comment(cid, v):
g.db.delete(save)
g.db.commit()
return {"message": "Comment unsaved!"}
return {"message": "Comment unsaved!"}

View File

@ -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':
with open("marseys.json", 'r') as f: marseys = loads(f.read().replace("'",'"')).keys()
marseys = cache.get("marseys").keys()
snappyquotes += [f':#{x}:' for x in marseys]
body = random.choice(snappyquotes)
body += "\n\n"

View File

@ -17,7 +17,7 @@ def privacy(v):
@app.get("/marseys")
@auth_required
def marseys(v):
with open("marseys.json", 'r') as f: marsey_count = list(loads(f.read().replace("'",'"')).items())
marsey_count = cache.get("marseys").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
with open("marseys.json", 'r') as f: marseys = loads(f.read().replace("'",'"'))
marseys = cache.get("marseys")
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):
with open("marseys.json", 'r') as f: return loads(f.read().replace("'",'"'))
return cache.get("marseys")
@app.get("/blocks")
@auth_required

View File

@ -31,7 +31,7 @@ def leaderboard_thread():
if SITE_NAME == 'Drama':
users13 = {}
with open("marseys.json", 'r') as f: authors = (x for x in loads(f.read().replace("'",'"')).values())
authors = (x for x in cache.get("marseys").values())
for x in authors:
if x["author"] in users13: users13[x["author"]] += 1
else: users13[x["author"]] = 1