[t-019] Create generate-setup-qr.py — QR code generator script #19

Open
opened 2026-07-05 08:31:02 +00:00 by david · 0 comments
Owner

Goal

Implement the QR code generation script that reads config.yaml and outputs a PNG for iOS app scanning.

References

Reference

  • DESIGN.md §4 QR Code Generation (scripts/generate-setup-qr.py)
  • AGENT.md §11 Config & Deployment

Implementation Steps

Implementation Steps

1. Create scripts/generate-setup-qr.py

Write the complete script:

#!/usr/bin/env python3
"""Generate a QR code for Keryx setup.

Reads the BFF config and outputs a QR code PNG that the iOS app
can scan from the SetupView to auto-configure the connection.

Usage:
  python scripts/generate-setup-qr.py [--output setup.png]
"""
import json
import sys
from pathlib import Path
import yaml
try:
    import qrcode
except ImportError:
    print("Install qrcode: uv add qrcode", file=sys.stderr)
    sys.exit(1)

config_path = Path.home() / ".keryx" / "config.yaml"
if not config_path.exists():
    print(f"Config not found at {config_path}", file=sys.stderr)
    sys.exit(1)

config = yaml.safe_load(config_path.read_text())

payload = {
    "v": 1,
    "url": f"https://{config['server']['host']}:{config['server']['port']}",
    "key": config["server"]["api_key"],
}

output_path = "keryx-setup.png"
for i, arg in enumerate(sys.argv):
    if arg == "--output" and i + 1 < len(sys.argv):
        output_path = sys.argv[i + 1]

img = qrcode.make(json.dumps(payload))
img.save(output_path)
print(f"QR code saved to {output_path}")

2. Make the script executable

cd /home/david/Projects/keryx-bff && chmod +x scripts/generate-setup-qr.py

Verification Gate

Verification Gate

Run:

cd /home/david/Projects/keryx-bff && python scripts/generate-setup-qr.py --output /tmp/test-qr.png 2>&1
# Expected: output contains 'QR code saved to'
ls -la /tmp/test-qr.png
# Expected: file exists, size > 0 bytes

STOP Conditions

STOP Conditions

  • If the script fails to create the PNG file, stop and check qrcode installation.

Depends on: t-002

## Goal Implement the QR code generation script that reads config.yaml and outputs a PNG for iOS app scanning. ## References ## Reference - DESIGN.md §4 QR Code Generation (scripts/generate-setup-qr.py) - AGENT.md §11 Config & Deployment ## Implementation Steps ## Implementation Steps ### 1. Create `scripts/generate-setup-qr.py` Write the complete script: ```python #!/usr/bin/env python3 """Generate a QR code for Keryx setup. Reads the BFF config and outputs a QR code PNG that the iOS app can scan from the SetupView to auto-configure the connection. Usage: python scripts/generate-setup-qr.py [--output setup.png] """ import json import sys from pathlib import Path import yaml try: import qrcode except ImportError: print("Install qrcode: uv add qrcode", file=sys.stderr) sys.exit(1) config_path = Path.home() / ".keryx" / "config.yaml" if not config_path.exists(): print(f"Config not found at {config_path}", file=sys.stderr) sys.exit(1) config = yaml.safe_load(config_path.read_text()) payload = { "v": 1, "url": f"https://{config['server']['host']}:{config['server']['port']}", "key": config["server"]["api_key"], } output_path = "keryx-setup.png" for i, arg in enumerate(sys.argv): if arg == "--output" and i + 1 < len(sys.argv): output_path = sys.argv[i + 1] img = qrcode.make(json.dumps(payload)) img.save(output_path) print(f"QR code saved to {output_path}") ``` ### 2. Make the script executable ```bash cd /home/david/Projects/keryx-bff && chmod +x scripts/generate-setup-qr.py ``` ## Verification Gate ## Verification Gate Run: ```bash cd /home/david/Projects/keryx-bff && python scripts/generate-setup-qr.py --output /tmp/test-qr.png 2>&1 # Expected: output contains 'QR code saved to' ls -la /tmp/test-qr.png # Expected: file exists, size > 0 bytes ``` ## STOP Conditions ## STOP Conditions - If the script fails to create the PNG file, stop and check qrcode installation. Depends on: t-002
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/keryx-bff#19
No description provided.