]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/blobdiff - app.py
Add last coffee pack button
[coffee/coffee-flask.git] / app.py
diff --git a/app.py b/app.py
index d66eff1219ff9bf2d68b7ce2d162436676242417..389aa2828c1e3017529a85de1772358ce3129425 100644 (file)
--- a/app.py
+++ b/app.py
@@ -12,6 +12,9 @@ import coffee_db as db
 import time
 from datetime import date, timedelta
 
+from json import loads
+from requests import post
+
 db.init_db()
 app = Flask(__name__)
 CORS(app, supports_credentials=True)
@@ -186,3 +189,22 @@ def log():
         print("Log:", data)
         return data
     return "nope"
+
+@app.route("/tellCoffeebot", methods=["POST"])
+def tell_coffeebot():
+    err = "Don't worry now! There is a NEW HOPE Tonda is buying NEW PACK!"
+    if request.method == "POST":
+        what = loads(request.data.decode("utf-8"))
+    try:
+        with open(".config", "r") as f:
+            conf = loads(f.read())
+    except:
+        return "Config needed! Please find in git history how it should look."
+    try:
+        res = post(conf["coffeebot"]["url"], json=what)
+        print("res is {}".format(res))
+    except:
+        err = "No connection! No covfefe! We all die here!"
+    if not res.ok:
+        err = "Slack don't like the request! It's discrimination!"
+    return err