master
Aevann1 2022-01-21 13:55:53 +02:00
parent 99cb289183
commit 18a9903086
6 changed files with 12 additions and 21 deletions

View File

@ -6,18 +6,15 @@ from flask import *
from flask_caching import Cache
from flask_limiter import Limiter
from flask_compress import Compress
from flask_limiter.util import get_remote_address
from flask_mail import Mail
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy import *
import gevent
from werkzeug.middleware.proxy_fix import ProxyFix
import redis
import time
from sys import stdout
import faulthandler
import atexit
app = Flask(__name__, template_folder='templates')
app.url_map.strict_slashes = False
@ -111,13 +108,6 @@ def after_request(response):
response.headers.add("X-Frame-Options", "deny")
return response
from files.routes import *
with open("marsey_count.json", 'r') as f: cache.set("marsey_count", loads(f.read()))
def close_running_threads():
with open("marsey_count.json", 'r') as f: marsey_file = loads(f.read())
print(marsey_count['marseylove'])
if marsey_file != marsey_count:
with open('marsey_count.json', 'w') as f: dump(marsey_count, f)
print("Marsey count saved!")
stdout.flush()
atexit.register(close_running_threads)
from files.routes import *

View File

@ -315,7 +315,7 @@ class User(Base):
return f"/@{self.username}"
def __repr__(self):
return f"<User(username={self.username})>"
return f"<User(id={self.id})>"
@property
@lazy

View File

@ -796,11 +796,4 @@ NOTIFIED_USERS = {
}
num_banners = len(listdir('files/assets/images/Drama/banners')) + 1
num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1
with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read())
marsey_counted = []
for k, val in marseys.items():
marsey_counted.append((k, val, marsey_count[k]))
marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True)
num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1

View File

@ -178,6 +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:
marsey_count = cache.get("marsey_count")
marseys_used = set()
for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized):
@ -259,6 +260,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] += 1
cache.set("marsey_count", marsey_count)
return sanitized

View File

@ -1211,6 +1211,7 @@ def admin_distinguish_comment(c_id, v):
@app.get("/admin/dump_cache")
@admin_level_required(2)
def admin_dump_cache(v):
with open('marsey_count.json', 'w') as f: dump(cache.get("marsey_count"), f)
cache.clear()
return {"message": "Internal cache cleared."}

View File

@ -17,6 +17,11 @@ def privacy(v):
@app.get("/marseys")
@auth_required
def emojis(v):
marsey_count = cache.get("marsey_count")
marsey_counted = []
for k, val in marseys.items():
marsey_counted.append((k, val, marsey_count[k]))
marsey_counted = sorted(marsey_counted, key=lambda x: x[2], reverse=True)
return render_template("marseys.html", v=v, marseys=marsey_counted)
@app.get("/terms")