From baa3a02a15e9d72de0c6cc5bae9431e6f7345bdd Mon Sep 17 00:00:00 2001 From: FKD13 <44001949+FKD13@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:39:39 +0100 Subject: [PATCH] add actions when pancacke is ready --- .tool-versions | 2 +- main.py | 25 +++++++++++++++++-------- requirements.txt | 1 + 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.tool-versions b/.tool-versions index 7e78d9a..b4736d5 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -python 3.10.4 +python 3.11.6 diff --git a/main.py b/main.py index c9f4414..4a7af03 100644 --- a/main.py +++ b/main.py @@ -2,8 +2,9 @@ import pickle from datetime import datetime import humanize -from flask import Flask, render_template, request, redirect, url_for +from flask import Flask, render_template, request, redirect from os.path import exists +from requests import post, exceptions app = Flask(__name__) @@ -62,6 +63,19 @@ def save_people(): people_file.close() +def update_index(index): + people[index].status += 1 + if people[index].status == 2: + try: + post('http://10.1.0.224:8080/blink') + post('http://10.1.2.3', data=f"ScrollingText >>> {people[index].name} <<< Enjoy! ") + post('http://10.1.2.3', data="Option text_trailingWhitespace 1") + except exceptions.ConnectionError: + print('Failed to blink the light') + elif people[index].status == 3: + people.remove(people[index]) + + @app.route("/") def home(): return render_template("home.html", people=people) @@ -73,15 +87,10 @@ def status_update(): result = request.form if "index" in result: index = int(request.form["index"]) - people[index].status += 1 - if people[index].status == 3: - people.remove(people[index]) + update_index(index) if "name" in result: index = people.index(Person(request.form["name"])) - print(index) - people[index].status += 1 - if people[index].status == 3: - people.remove(people[index]) + update_index(index) save_people() return redirect("/") diff --git a/requirements.txt b/requirements.txt index a4dd161..608e037 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ flask humanize +requests