Skip to content

Instantly share code, notes, and snippets.

@bjyurkovich
Last active October 19, 2019 04:13
Show Gist options
  • Select an option

  • Save bjyurkovich/e5129491d7ae25cbe73a36523c1e6fbc to your computer and use it in GitHub Desktop.

Select an option

Save bjyurkovich/e5129491d7ae25cbe73a36523c1e6fbc to your computer and use it in GitHub Desktop.
from flask import Flask, jsonify, request
import requests
import os
# Create my flask app to run on Port 7500
app = Flask(__name__)
PORT = 7500
# Handler for Fred's data (receiving the iotery Post Data Webhook)
@app.route("/light-status", methods=["POST"])
def handle_data_webhook():
body = request.json
print(body)
# Get the status out of the webhook body
status = body["in"]["packets"][0]["data"]["light_state"]
# Post to slack webhook we created
requests.post(
"https://hooks.slack.com/services/TKQ7F5C3A/BPMKH0Z54/...",
json={"text": "Fred says that he is currently " + ("on" if status == 1 else "off")}
)
return jsonify({"status": "OK"})
if __name__ == "__main__":
app.run(debug=True, port=PORT, host="0.0.0.0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment