Created
November 19, 2019 18:52
-
-
Save i5okie/0e71599b5f6604b3dd584b4a2d4aae32 to your computer and use it in GitHub Desktop.
python webhook echo server with coloured formatted output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, ast | |
from flask import Flask, request, abort | |
from pygments import highlight, lexers, formatters | |
app = Flask(__name__) | |
@app.route('/webhook', methods=['POST']) | |
def webhook(): | |
if request.method == 'POST': | |
formatted_json = json.dumps(request.json, indent=2, sort_keys=True) | |
print(request.headers) | |
print(highlight(unicode(formatted_json, 'UTF-8'), lexers.JsonLexer(), formatters.TerminalFormatter())) | |
return '', 200 | |
else: | |
abort(400) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment