replaces hardcoded values with env var
This commit is contained in:
@@ -26,6 +26,15 @@ It progresses **only during your scheduled work hours**
|
||||
- During the day, the bar fills smoothly
|
||||
- End of Wednesday = **100% freedom**
|
||||
|
||||
### Configuration
|
||||
|
||||
| Variable | Default | Description |
|
||||
|--------|---------|-------------|
|
||||
| WORK_START_TIME | 07:00 | Workday start (HH:MM) |
|
||||
| WORK_END_TIME | 17:30 | Workday end (HH:MM) |
|
||||
| WORK_DAYS | 0,1,2,3 | JS day numbers (Sun=0) |
|
||||
| UPDATE_INTERVAL_MS | 60000 | Update frequency |
|
||||
|
||||
---
|
||||
|
||||
## 🛠 Tech Stack
|
||||
|
||||
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)
|
||||
|
||||
@@ -25,14 +25,34 @@
|
||||
<div class="percent weekly-percent" id="weeklyPercent">0%</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const WORK_START_HOUR = 7;
|
||||
const WORK_START_MINUTE = 0;
|
||||
const WORK_END_HOUR = 17;
|
||||
const WORK_END_MINUTE = 30;
|
||||
<!-- App configuration -->
|
||||
<script id="app-config" type="application/json">
|
||||
{{ {
|
||||
"workStart": work_start,
|
||||
"workEnd": work_end,
|
||||
"workDays": work_days,
|
||||
"updateInterval": update_interval
|
||||
} | tojson }}
|
||||
</script>
|
||||
|
||||
<!-- Application logic -->
|
||||
<script>
|
||||
const config = JSON.parse(
|
||||
document.getElementById("app-config").textContent
|
||||
);
|
||||
|
||||
const WORK_START_HOUR = config.workStart.hour;
|
||||
const WORK_START_MINUTE = config.workStart.minute;
|
||||
const WORK_END_HOUR = config.workEnd.hour;
|
||||
const WORK_END_MINUTE = config.workEnd.minute;
|
||||
|
||||
const WORK_DAYS = config.workDays;
|
||||
const UPDATE_INTERVAL = config.updateInterval;
|
||||
|
||||
const TOTAL_WORK_MINUTES =
|
||||
(WORK_END_HOUR * 60 + WORK_END_MINUTE) -
|
||||
(WORK_START_HOUR * 60 + WORK_START_MINUTE);
|
||||
|
||||
const TOTAL_WORK_MINUTES = 630; // 10.5 hours
|
||||
const WORK_DAYS = [0, 1, 2, 3]; // Sunday → Wednesday
|
||||
const WEEKLY_DAY_WEIGHT = 100 / WORK_DAYS.length;
|
||||
|
||||
function updateProgress() {
|
||||
@@ -64,16 +84,19 @@
|
||||
statusText.textContent = "Workday complete 🎉";
|
||||
} else {
|
||||
const elapsedMinutes = Math.floor((now - start) / 60000);
|
||||
dailyPercent = Math.min((elapsedMinutes / TOTAL_WORK_MINUTES) * 100, 100);
|
||||
dailyPercent = Math.min(
|
||||
(elapsedMinutes / TOTAL_WORK_MINUTES) * 100,
|
||||
100
|
||||
);
|
||||
statusText.textContent = "Grinding…";
|
||||
}
|
||||
|
||||
// Apply daily progress
|
||||
// Daily progress
|
||||
dailyFill.style.width = dailyPercent + "%";
|
||||
dailyPercentText.textContent = dailyPercent.toFixed(1) + "%";
|
||||
|
||||
// Weekly progress
|
||||
let completedDays = WORK_DAYS.filter(d => d < day).length;
|
||||
const completedDays = WORK_DAYS.filter(d => d < day).length;
|
||||
let weeklyPercent =
|
||||
(completedDays * WEEKLY_DAY_WEIGHT) +
|
||||
(isWorkday ? (dailyPercent / 100) * WEEKLY_DAY_WEIGHT : 0);
|
||||
@@ -85,7 +108,7 @@
|
||||
}
|
||||
|
||||
updateProgress();
|
||||
setInterval(updateProgress, 30 * 1000);
|
||||
setInterval(updateProgress, UPDATE_INTERVAL);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user