From 2d4b503f36b4c0b9bf9e3f69101e03ade1887766 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 22 Nov 2020 12:29:29 -0800 Subject: [PATCH] add cmd to delete posts that are too shit --- bin/cmd | 2 +- suchwow/app.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/cmd b/bin/cmd index 45dc9bb..fcd4f8b 100755 --- a/bin/cmd +++ b/bin/cmd @@ -4,4 +4,4 @@ source .venv/bin/activate export FLASK_APP=suchwow/app.py export FLASK_SECRETS=config.py export FLASK_DEBUG=1 -flask $1 +flask $@ diff --git a/suchwow/app.py b/suchwow/app.py index d6be722..46a326d 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -1,7 +1,8 @@ import json +import click from datetime import datetime, timedelta from random import choice -from os import makedirs +from os import makedirs, path, remove from flask import Flask, request, session, redirect from flask import render_template, flash, url_for from flask_session import Session @@ -103,5 +104,15 @@ def payout_users(): sweep = wallet.sweep_all(account=post.account_index, dest_address=submitter.address) print(sweep) +@app.cli.command("delete_post") +@click.argument("post_id") +def delete_post(post_id): + post = Post.get(id=post_id) + save_path_base = path.join(app.config["DATA_FOLDER"], "uploads") + save_path = path.join(save_path_base, post.image_name) + post.delete_instance() + remove(save_path) + print(f"Deleted post {post_id} and image {save_path}") + if __name__ == "__main__": app.run()