replaces hardcoded values with env var
This commit is contained in:
35
app.py
35
app.py
@@ -1,10 +1,41 @@
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def parse_time(value, default):
|
||||
try:
|
||||
hour, minute = map(int, value.split(":"))
|
||||
return {"hour": hour, "minute": minute}
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
start_time = parse_time(
|
||||
os.getenv("WORK_START_TIME", "07:00"),
|
||||
{"hour": 7, "minute": 0}
|
||||
)
|
||||
end_time = parse_time(
|
||||
os.getenv("WORK_END_TIME", "17:30"),
|
||||
{"hour": 17, "minute": 30}
|
||||
)
|
||||
|
||||
work_days = [
|
||||
int(d.strip())
|
||||
for d in os.getenv("WORK_DAYS", "0,1,2,3").split(",")
|
||||
if d.strip().isdigit()
|
||||
]
|
||||
|
||||
update_interval = int(os.getenv("UPDATE_INTERVAL_MS", "60000"))
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
work_start=start_time,
|
||||
work_end=end_time,
|
||||
work_days=work_days,
|
||||
update_interval=update_interval
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
|
||||
Reference in New Issue
Block a user