Last active
October 9, 2024 00:57
-
-
Save benrules2/c4f3db455f4f2dfbe7d5b825b0b4ee36 to your computer and use it in GitHub Desktop.
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 water | |
if __name__ == "__main__": | |
water.auto_water() |
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
from flask import Flask, render_template, redirect, url_for | |
import psutil | |
import datetime | |
import water | |
import os | |
app = Flask(__name__) | |
def template(title = "HELLO!", text = ""): | |
now = datetime.datetime.now() | |
timeString = now | |
templateDate = { | |
'title' : title, | |
'time' : timeString, | |
'text' : text | |
} | |
return templateDate | |
@app.route("/") | |
def hello(): | |
templateData = template() | |
return render_template('main.html', **templateData) | |
@app.route("/last_watered") | |
def check_last_watered(): | |
templateData = template(text = water.get_last_watered()) | |
return render_template('main.html', **templateData) | |
@app.route("/sensor") | |
def action(): | |
status = water.get_status() | |
message = "" | |
if (status == 1): | |
message = "Water me please!" | |
else: | |
message = "I'm a happy plant" | |
templateData = template(text = message) | |
return render_template('main.html', **templateData) | |
@app.route("/water") | |
def action2(): | |
water.pump_on() | |
templateData = template(text = "Watered Once") | |
return render_template('main.html', **templateData) | |
@app.route("/auto/water/<toggle>") | |
def auto_water(toggle): | |
running = False | |
if toggle == "ON": | |
templateData = template(text = "Auto Watering On") | |
for process in psutil.process_iter(): | |
try: | |
if process.cmdline()[1] == 'auto_water.py': | |
templateData = template(text = "Already running") | |
running = True | |
except: | |
pass | |
if not running: | |
os.system("python3.4 auto_water.py&") | |
else: | |
templateData = template(text = "Auto Watering Off") | |
os.system("pkill -f water.py") | |
return render_template('main.html', **templateData) | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=80, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment