Skip to content

Commit 5869559

Browse files
authored
Merge pull request #357 from cs50/add-msg
add motivational msgs
2 parents cdbdfdb + dcd23d6 commit 5869559

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

check50/renderer/_renderers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import pathlib
3+
import random
34

45
import jinja2
56
import termcolor
@@ -71,8 +72,10 @@ def to_json(slug, results, version):
7172

7273
def to_ansi(slug, results, version, _log=False):
7374
lines = [termcolor.colored(_("Results for {} generated by check50 v{}").format(slug, version), "white", attrs=["bold"])]
75+
num_passed = 0
7476
for result in results:
7577
if result["passed"]:
78+
num_passed += 1
7679
lines.append(termcolor.colored(f":) {result['description']}", "green"))
7780
elif result["passed"] is None:
7881
lines.append(termcolor.colored(f":| {result['description']}", "yellow"))
@@ -89,5 +92,15 @@ def to_ansi(slug, results, version, _log=False):
8992

9093
if _log:
9194
lines += (f" {line}" for line in result["log"])
95+
96+
if not all(result["passed"] for result in results) and num_passed > len(results) // 2:
97+
if random.random() < 0.20:
98+
message = random.choice([
99+
"~~~~~ You can do it! ~~~~~",
100+
"~~~~~ Keep it up! ~~~~~",
101+
"~~~~~ You're getting there! ~~~~~"
102+
])
103+
lines.append(termcolor.colored(message, "magenta"))
104+
92105
return "\n".join(lines)
93106

0 commit comments

Comments
 (0)