Skip to content

Instantly share code, notes, and snippets.

@blha303
Created February 9, 2016 08:30
Show Gist options
  • Save blha303/39e0d74c4f1ce220f909 to your computer and use it in GitHub Desktop.
Save blha303/39e0d74c4f1ce220f909 to your computer and use it in GitHub Desktop.
A flask web server to start/stop weechat for a Glowing Bear connection. Intended for people who have push notifications set up in their bouncer that only come through when no clients are connected
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment