Skip to content

Fix Stern Game logos#509

Closed
brombomb wants to merge 1 commit into
mainfrom
fix-stern
Closed

Fix Stern Game logos#509
brombomb wants to merge 1 commit into
mainfrom
fix-stern

Conversation

@brombomb
Copy link
Copy Markdown
Collaborator

New API old logos

@brombomb brombomb requested a review from tavdog as a code owner May 20, 2026 22:28
@brombomb brombomb changed the title fix logos Fix Stern Game logos May 20, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +116 to +122
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]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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"]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loop now iterates over g["scores"] instead of the local scores variable. This causes the highest_only filter (applied on lines 220-225) to be ignored, as it modifies the local scores list but not the one inside the g dictionary.

Suggested change
for s in g["scores"]:
for s in scores:

Comment on lines +130 to +132
if end1 == -1: end1 = 999999
if end2 == -1: end2 = 999999
s_end = end1 if end1 < end2 else end2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of a magic number like 999999 to handle missing delimiters is fragile. A more robust approach would be to check if the indices are valid (not -1) and use the minimum of the valid ones.

Comment on lines +171 to +172
"c1": c1,
"c2": c2,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. 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"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the pre-calculated middle color instead of calling the function repeatedly.

Suggested change
model_color = mid_color(g["c1"], g["c2"])
model_color = g.get("mid_c", "#666")
References
  1. Local variables should use snake_case (e.g., model_color) to distinguish them from global constants, following PEP 8 conventions. (link)

Comment on lines +153 to +157
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for finding the end of the URL using a magic number 999999 is fragile. Additionally, this parsing logic is duplicated from stern_high_scores.star. Consider a more robust way to detect the closing delimiter for the URL.

@brombomb brombomb closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant