start_weechat.py
· 931 B · Python
Raw
from flask import *
from subprocess import check_output, CalledProcessError
app = Flask(__name__)
@app.route('/')
def index():
if request.args.get("pw", None) and request.args["pw"] == "somepassword":
if "start" in request.args:
try:
_ = check_output(["pidof", "weechat"])
except CalledProcessError:
pass
else:
_ = check_output(["killall", "weechat"])
_ = check_output(["screen", "-dmS", "irc", "weechat"])
return redirect("https://glowing-bear.github.io/glowing-bear", code=302)
elif "stop" in request.args:
try:
_ = check_output(["killall", "weechat"])
return "Done.\n"
except CalledProcessError:
return "Nothing to stop.\n"
else:
return "Go away.\n"
if __name__ == "__main__":
app.run(port=56788, debug=True)
| 1 | from flask import * |
| 2 | from subprocess import check_output, CalledProcessError |
| 3 | |
| 4 | app = Flask(__name__) |
| 5 | |
| 6 | @app.route('/') |
| 7 | def index(): |
| 8 | if request.args.get("pw", None) and request.args["pw"] == "somepassword": |
| 9 | if "start" in request.args: |
| 10 | try: |
| 11 | _ = check_output(["pidof", "weechat"]) |
| 12 | except CalledProcessError: |
| 13 | pass |
| 14 | else: |
| 15 | _ = check_output(["killall", "weechat"]) |
| 16 | _ = check_output(["screen", "-dmS", "irc", "weechat"]) |
| 17 | return redirect("https://glowing-bear.github.io/glowing-bear", code=302) |
| 18 | elif "stop" in request.args: |
| 19 | try: |
| 20 | _ = check_output(["killall", "weechat"]) |
| 21 | return "Done.\n" |
| 22 | except CalledProcessError: |
| 23 | return "Nothing to stop.\n" |
| 24 | else: |
| 25 | return "Go away.\n" |
| 26 | |
| 27 | if __name__ == "__main__": |
| 28 | app.run(port=56788, debug=True) |
| 29 |