From 7b97f93051890a7b0f5dcbac998b96404c4a882c Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 26 Mar 2025 07:01:19 -1000 Subject: [PATCH] style: Reformat code with linter --- scripts/30k-image.py | 75 +++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/scripts/30k-image.py b/scripts/30k-image.py index e9db4078b..cfee7cd9d 100644 --- a/scripts/30k-image.py +++ b/scripts/30k-image.py @@ -4,10 +4,10 @@ Generate a celebratory SVG image for Aider reaching 30,000 GitHub stars. This creates a shareable social media graphic with confetti animation. """ +import argparse +import base64 import os import random -import base64 -import argparse from pathlib import Path # Default colors for the celebration image @@ -25,26 +25,28 @@ DEFAULT_HEIGHT = 630 def embed_font(): """Returns base64 encoded font data for the GlassTTYVT220 font.""" # Path to the font file - font_path = Path(__file__).parent.parent / "aider" / "website" / "assets" / "Glass_TTY_VT220.ttf" - + font_path = ( + Path(__file__).parent.parent / "aider" / "website" / "assets" / "Glass_TTY_VT220.ttf" + ) + # If font file doesn't exist, return empty string if not font_path.exists(): print(f"Warning: Font file not found at {font_path}") return "" - + # Read and encode the font file with open(font_path, "rb") as f: font_data = f.read() - + # Return base64 encoded font data - return base64.b64encode(font_data).decode('utf-8') + return base64.b64encode(font_data).decode("utf-8") def generate_confetti(count=150, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT): """Generate SVG confetti elements for the celebration.""" confetti = [] colors = [AIDER_GREEN, AIDER_BLUE, GOLD_COLOR, "#e74c3c", "#9b59b6", "#3498db", "#2ecc71"] - + for i in range(count): x = random.randint(0, width) y = random.randint(0, height) @@ -53,10 +55,10 @@ def generate_confetti(count=150, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT): rotation = random.randint(0, 360) delay = random.uniform(0, 2) duration = random.uniform(1, 3) - + # Randomly choose between rect (square), circle, and star shapes shape_type = random.choice(["rect", "circle", "star"]) - + if shape_type == "rect": shape = f""" @@ -76,13 +78,13 @@ def generate_confetti(count=150, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT): x_point = x + (size * 0.5) * math.cos(angle) y_point = y + (size * 0.5) * math.sin(angle) points.append(f"{x_point},{y_point}") - + # Inner points of the star inner_angle = angle + 3.14159 / 5 inner_x = x + (size * 0.2) * math.cos(inner_angle) inner_y = y + (size * 0.2) * math.sin(inner_angle) points.append(f"{inner_x},{inner_y}") - + points_str = " ".join(points) shape = f""" @@ -90,9 +92,9 @@ def generate_confetti(count=150, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT): """ - + confetti.append(shape) - + return "\n".join(confetti) @@ -100,7 +102,7 @@ def generate_celebration_svg(output_path=None, width=DEFAULT_WIDTH, height=DEFAU """Generate a celebratory SVG for 30K GitHub stars.""" # Import math here to avoid the error in generate_confetti import math - + # Font embedding font_data = embed_font() font_face = f""" @@ -111,10 +113,10 @@ def generate_celebration_svg(output_path=None, width=DEFAULT_WIDTH, height=DEFAU font-style: normal; }} """ if font_data else "" - + # Generate confetti elements confetti = generate_confetti(count=150, width=width, height=height) - + # Create the SVG content svg_content = f""" @@ -173,25 +175,42 @@ def generate_celebration_svg(output_path=None, width=DEFAULT_WIDTH, height=DEFAU """ - + # Write to file if output path is specified if output_path: - with open(output_path, 'w') as f: + with open(output_path, "w") as f: f.write(svg_content) print(f"Celebration SVG saved to {output_path}") - + return svg_content if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Generate a celebration SVG for Aider's 30K GitHub stars") - parser.add_argument('--output', '-o', type=str, default="aider-30k-stars.svg", - help="Output file path (default: aider-30k-stars.svg)") - parser.add_argument('--width', '-w', type=int, default=DEFAULT_WIDTH, - help=f"Image width in pixels (default: {DEFAULT_WIDTH})") - parser.add_argument('--height', '-ht', type=int, default=DEFAULT_HEIGHT, - help=f"Image height in pixels (default: {DEFAULT_HEIGHT})") + parser = argparse.ArgumentParser( + description="Generate a celebration SVG for Aider's 30K GitHub stars" + ) + parser.add_argument( + "--output", + "-o", + type=str, + default="aider-30k-stars.svg", + help="Output file path (default: aider-30k-stars.svg)", + ) + parser.add_argument( + "--width", + "-w", + type=int, + default=DEFAULT_WIDTH, + help=f"Image width in pixels (default: {DEFAULT_WIDTH})", + ) + parser.add_argument( + "--height", + "-ht", + type=int, + default=DEFAULT_HEIGHT, + help=f"Image height in pixels (default: {DEFAULT_HEIGHT})", + ) args = parser.parse_args() - + # Generate the SVG generate_celebration_svg(args.output, args.width, args.height)