style: Reformat code with linter

This commit is contained in:
Paul Gauthier (aider) 2025-03-26 07:01:19 -10:00
parent 02bc926d75
commit 7b97f93051

View file

@ -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"""<rect x="{x}" y="{y}" width="{size}" height="{size}" fill="{color}"
transform="rotate({rotation}, {x + size/2}, {y + size/2})">
@ -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"""<polygon points="{points_str}" fill="{color}"
transform="rotate({rotation}, {x}, {y})">
@ -90,9 +92,9 @@ def generate_confetti(count=150, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT):
<animate attributeName="transform" from="rotate({rotation}, {x}, {y})" to="rotate({rotation + 360}, {x}, {y})" dur="{duration*2}s" begin="{delay}s" repeatCount="indefinite" />
<animate attributeName="cy" from="{y}" to="{y + random.randint(200, 400)}" dur="{duration}s" begin="{delay}s" repeatCount="indefinite" />
</polygon>"""
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"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="{width}" height="{height}" viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
@ -173,25 +175,42 @@ def generate_celebration_svg(output_path=None, width=DEFAULT_WIDTH, height=DEFAU
</g>
</svg>
"""
# 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)