def main(): args = sys.argv[1:] if args: if args[0] == "init_db": Base.metadata.create_all(engine) if args[0] == "add": paste = Paste("<html>hi</html>", lexer="html", expiry=timedelta(seconds=5)) session.add(paste) session.commit() if args[0] == "remove": paste = session.query(Paste).filter(Paste.id == int(args[1])).first() session.delete(paste) session.commit() if args[0] == "list": for paste in session.query(Paste).all(): print(paste) if args[0] == "reap": pastes = session.query(Paste).filter(Paste.exp_date < datetime.utcnow()).all() for paste in pastes: session.delete(paste) session.commit() print("Reaped {} expired pastes".format(len(pastes)))
def remove(removal_id): paste = session.query(Paste).filter(Paste.removal_id == removal_id).first() if not paste: return render_template("404.html"), 404 session.delete(paste) session.commit() return redirect(url_for("index"))
def remove_json(): paste = session.query(Paste).filter(Paste.removal_id == request.form["removal_id"]).first() if not paste: return "not found", 404 session.delete(paste) session.commit() response = make_response(json.dumps([{"paste_id": paste.paste_id, "status": "removed"}])) response.headers["content-type"] = "application/json" return response