From aec88afc0d3467c3bd299d70ce52961af6a2fa84 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 31 Aug 2022 23:33:10 -0700 Subject: [PATCH] cleanup --- suchwow/app.py | 3 +-- suchwow/filters.py | 2 +- suchwow/models.py | 4 +++- suchwow/routes/api.py | 1 + suchwow/routes/auth.py | 4 +++- suchwow/routes/comment.py | 30 ------------------------------ suchwow/routes/leaderboard.py | 11 +++-------- suchwow/routes/post.py | 11 +++++------ suchwow/utils/helpers.py | 20 +------------------- 9 files changed, 18 insertions(+), 68 deletions(-) delete mode 100644 suchwow/routes/comment.py diff --git a/suchwow/app.py b/suchwow/app.py index 3a3201f..275bdfa 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -1,7 +1,7 @@ from flask import Flask from flask_session import Session -from suchwow.routes import auth, comment, post, profile, leaderboard, api, mod, main +from suchwow.routes import auth, post, profile, leaderboard, api, mod, main from suchwow import filters, cli @@ -13,7 +13,6 @@ Session(app) app.register_blueprint(post.bp) app.register_blueprint(auth.bp) app.register_blueprint(profile.bp) -app.register_blueprint(comment.bp) app.register_blueprint(leaderboard.bp) app.register_blueprint(api.bp) app.register_blueprint(mod.bp) diff --git a/suchwow/filters.py b/suchwow/filters.py index c370cf0..60edc4c 100644 --- a/suchwow/filters.py +++ b/suchwow/filters.py @@ -1,4 +1,4 @@ -from flask import Blueprint, current_app +from flask import Blueprint from arrow import get as arrow_get from suchwow.models import Moderator diff --git a/suchwow/models.py b/suchwow/models.py index 6296dfa..b46c09e 100644 --- a/suchwow/models.py +++ b/suchwow/models.py @@ -1,8 +1,10 @@ -from peewee import * from random import choice from os import path from datetime import datetime + +from peewee import * from PIL import Image + from suchwow import wownero from suchwow import config diff --git a/suchwow/routes/api.py b/suchwow/routes/api.py index 2135e3a..cff07f9 100644 --- a/suchwow/routes/api.py +++ b/suchwow/routes/api.py @@ -1,4 +1,5 @@ from flask import jsonify, Blueprint, url_for, request, abort + from suchwow.models import Post from suchwow import wownero diff --git a/suchwow/routes/auth.py b/suchwow/routes/auth.py index 78e0b0f..b066e53 100644 --- a/suchwow/routes/auth.py +++ b/suchwow/routes/auth.py @@ -1,6 +1,8 @@ -import requests from uuid import uuid4 + +import requests from flask import session, redirect, url_for, request, Blueprint + from suchwow import config diff --git a/suchwow/routes/comment.py b/suchwow/routes/comment.py deleted file mode 100644 index ae85d65..0000000 --- a/suchwow/routes/comment.py +++ /dev/null @@ -1,30 +0,0 @@ -from flask import render_template, Blueprint, flash -from flask import request, redirect, url_for, session -from suchwow.models import Post, Comment, Profile -from suchwow.utils.decorators import login_required - - -bp = Blueprint("comment", "comment") - -@bp.route("/comment/create/post/", methods=["GET", "POST"]) -@login_required -def create(post_id): - if not Post.filter(id=post_id): - flash("WTF, that post doesn't exist. Stop it, hackerman.", "is-danger") - return redirect(url_for("main.index")) - - if request.method == "POST": - comment_text = request.form.get("comment") - if len(comment_text) > 300: - flash("WTF, too many characters to post, asshole.", "is-danger") - return redirect(request.url) - commenter = Profile.get(username=session["auth"]["preferred_username"]) - post = Post.get(id=post_id) - c = Comment( - comment=comment_text, - commenter=commenter, - post=post, - ) - c.save() - return redirect(url_for("post.read", id=post_id)) - return render_template("comment/create.html") diff --git a/suchwow/routes/leaderboard.py b/suchwow/routes/leaderboard.py index 3a17f81..93cd575 100644 --- a/suchwow/routes/leaderboard.py +++ b/suchwow/routes/leaderboard.py @@ -1,11 +1,6 @@ -from datetime import datetime, timedelta -from os import path -from flask import render_template, Blueprint, request, session -from flask import send_from_directory, redirect, url_for, current_app -from werkzeug.utils import secure_filename -from suchwow import wownero -from suchwow.models import Post -from suchwow.utils.helpers import rw_cache, get_top_posters, get_top_posts +from flask import render_template, Blueprint, request + +from suchwow.utils.helpers import get_top_posters, get_top_posts bp = Blueprint("leaderboard", "leaderboard") diff --git a/suchwow/routes/post.py b/suchwow/routes/post.py index 0f24a61..11acec5 100644 --- a/suchwow/routes/post.py +++ b/suchwow/routes/post.py @@ -1,19 +1,18 @@ -from datetime import datetime, timedelta from os import path, remove from io import BytesIO from base64 import b64encode -from sys import audit +from secrets import token_urlsafe + from qrcode import make as qrcode_make -from flask import render_template, Blueprint, request, session, flash +from flask import render_template, Blueprint, request, flash from flask import send_from_directory, redirect, url_for, current_app from werkzeug.utils import secure_filename -from secrets import token_urlsafe + from suchwow import wownero -from suchwow import config from suchwow.models import Post, Profile, Comment, Ban from suchwow.utils.decorators import login_required, profile_required, moderator_required from suchwow.utils.helpers import allowed_file, is_moderator, get_session_user -from suchwow.utils.helpers import post_webhook, audit_event +from suchwow.utils.helpers import audit_event from suchwow.discord import post_discord_webhook diff --git a/suchwow/utils/helpers.py b/suchwow/utils/helpers.py index 3846db1..feb1338 100644 --- a/suchwow/utils/helpers.py +++ b/suchwow/utils/helpers.py @@ -1,10 +1,8 @@ import pickle from os import path from datetime import datetime, timedelta -from json import dumps -from requests import post as r_post -from flask import session, current_app +from flask import session from suchwow.models import Moderator, Post, AuditEvent, Profile from suchwow.wownero import Wallet, from_atomic @@ -35,22 +33,6 @@ def get_session_user(): return None return session["auth"]["preferred_username"].strip() -def post_webhook(msg): - try: - if current_app.config["DEBUG"]: - msg = "[DEBUG] " + msg - data = { - "text": msg, - "channel": config.MM_CHANNEL, - "username": config.MM_USERNAME, - "icon_url": config.MM_ICON - } - res = r_post(config.MM_ENDPOINT, data=dumps(data)) - res.raise_for_status() - return True - except: - return False - def get_latest_tipped_posts(): key_name = 'latest_tips' posts = []