Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions weekly_habit_progress_chart/weekly_habit_progress_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Weekly Habit Progress Chart Generator (Under 100 lines)
# Issue: https://github.com/sumanth-0/100LinesOfPythonCode/issues/636
# Usage: Run and enter habit completions (Y/N or 1/0) for Mon-Sun. Saves ASCII chart.

DAYS = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]

def get_inputs():
print("Enter habit name (e.g., Reading):")
habit = input("Habit: ").strip() or "Habit"
print("Enter completion for each day as 1/0 or Y/N. Press Enter to skip (0).")
vals = []
for d in DAYS:
v = input(f"{d}: ").strip().lower()
vals.append(1 if v in ("1","y","yes","true","t") else 0)
return habit, vals

def pct(vals):
return round(100 * sum(vals) / max(1,len(vals)))

def bar(n, total=7, fill="█", empty="·"):
filled = int(n)
return fill*filled + empty*(total-filled)

def weekly_chart(habit, vals):
total = sum(vals)
print("\n=== Weekly Habit Progress ===")
print(f"Habit: {habit}")
print("Days : " + " ".join(f"{d:>3}" for d in DAYS))
print("Done : " + " ".join(" ✔ " if v else " " for v in vals))
print(f"Total: {total}/7 ({pct(vals)}%)")
print("Progress:")
# 7-slot horizontal bar (one per day)
print("[" + bar(total, 7) + "]")
# Sparkline-like row
print("Spark : " + "".join("▇" if v else "▁" for v in vals))

def save_chart(habit, vals, path="weekly_habit_progress_chart/chart.txt"):
import os
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", encoding="utf-8") as f:
f.write("=== Weekly Habit Progress ===\n")
f.write(f"Habit: {habit}\n")
f.write("Days : " + " ".join(f"{d:>3}" for d in DAYS) + "\n")
f.write("Done : " + " ".join("✔" if v else "-" for v in vals) + "\n")
f.write(f"Total: {sum(vals)}/7 ({pct(vals)}%)\n")
f.write("Progress:\n")
f.write("[" + bar(sum(vals), 7) + "]\n")
f.write("Spark : " + "".join("▇" if v else "▁" for v in vals) + "\n")
return path

if __name__ == "__main__":
habit, vals = get_inputs()
weekly_chart(habit, vals)
out = save_chart(habit, vals)
print(f"\nSaved chart to: {out}")