Conversation
There was a problem hiding this comment.
Code Review
This pull request implements dynamic logo and color extraction for Stern Pinball apps by scraping metadata from their web service. The review identified a critical bug in stern_high_scores.star where score filtering is bypassed. Feedback also highlighted brittle string parsing logic for hex colors and URLs, recommending more robust delimiter detection over magic numbers and fixed-length slicing. Suggestions were provided to optimize performance by pre-calculating colors and to adhere to snake_case naming conventions.
| c1 = games_body[hex_start:hex_start+7] | ||
|
|
||
| g2_idx = games_body.find('gradient_stop', idx, idx + 5000) | ||
| if g2_idx > -1: | ||
| hex_start = games_body.find('#', g2_idx, g2_idx + 50) | ||
| if hex_start > -1: | ||
| c2 = games_body[hex_start:hex_start+7] |
There was a problem hiding this comment.
Extracting a fixed 7 characters for hex colors (lines 116 and 122) is brittle. If the source string uses 3-digit hex codes or if the field is followed immediately by a quote or backslash, color.hex() will receive an invalid string and fail. It is safer to find the actual end of the value by searching for the closing quote.
| # Build personal score table | ||
| score_rows = [] | ||
| for s in scores: | ||
| for s in g["scores"]: |
There was a problem hiding this comment.
| if end1 == -1: end1 = 999999 | ||
| if end2 == -1: end2 = 999999 | ||
| s_end = end1 if end1 < end2 else end2 |
| "c1": c1, | ||
| "c2": c2, |
There was a problem hiding this comment.
Pre-calculate the middle color here to avoid redundant calls to mid_color inside the rendering loop in main.
"c1": c1,
"c2": c2,
"mid_c": mid_color(c1, c2),
References
- Local variables should use snake_case (e.g., mid_c) to distinguish them from global constants, following PEP 8 conventions. (link)
| if s["model"] == "pro": | ||
| model_color = g["c1"] | ||
| elif s["model"] == "premium": | ||
| model_color = mid_color(g["c1"], g["c2"]) |
There was a problem hiding this comment.
Use the pre-calculated middle color instead of calling the function repeatedly.
| model_color = mid_color(g["c1"], g["c2"]) | |
| model_color = g.get("mid_c", "#666") |
References
- Local variables should use snake_case (e.g., model_color) to distinguish them from global constants, following PEP 8 conventions. (link)
| end1 = games_body.find('\\"', http_start) | ||
| end2 = games_body.find('"', http_start) | ||
| if end1 == -1: end1 = 999999 | ||
| if end2 == -1: end2 = 999999 | ||
| s_end = end1 if end1 < end2 else end2 |
New API old logos