Skip to content

Add helper script to set PEXELS_API_KEY safely - #966

Open
yoyo8080y wants to merge 1 commit into
OpenMontageInc:mainfrom
yoyo8080y:main
Open

yoyo8080y wants to merge 1 commit into
OpenMontageInc:mainfrom
yoyo8080y:main

Conversation

@yoyo8080y

Copy link
Copy Markdown

Summary

Adds scripts/set_pexels_key.sh, a small helper that prompts for the Pexels API key with hidden input, validates it, and writes it into .env. Editing .env by hand can go wrong silently: with a non-English keyboard layout active, the value saved can end up as non-ASCII text. Every Pexels search then crashes with a UnicodeEncodeError: 'latin-1' codec can't encode characters when the key goes into the request header. Nothing tells the user the key itself is the problem.

Related issue

None.

Changes

  • scripts/set_pexels_key.sh (new): reads the key with read -s. It writes the key into the PEXELS_API_KEY= line of .env only if the input is 30 or more ASCII letters and digits. Otherwise it prints NOT saved with where to copy the key from, and leaves .env unchanged.
  • .env.example: one comment line next to PEXELS_API_KEY pointing to the script.

Testing

  • Ran the script against a temporary copy of .env.example:
    • Arabic text as input → NOT saved, exit code 1, and PEXELS_API_KEY= stays empty.
    • A 56-character alphanumeric value → saved, exit code 0, and the line is updated.
  • Found while setting up on macOS (zsh, Apple Silicon). The script uses zsh syntax (read "k?prompt", ${0:A:h}) and BSD sed -i '', so as written it targets macOS. I can make it portable to bash/GNU sed if you'd rather.

Checklist

  • The change is focused on a single logical concern.
  • I ran the relevant tests locally (make test-contracts / make test) where applicable. Not applicable: no Python code changed.
  • I updated docs/README if behavior or usage changed. Added a pointer in .env.example.
  • No unrelated files (build artifacts, local config) are included in the diff.

Note for reviewers (separate issue, not fixed here)

On the same setup, Piper TTS (piper-tts 1.8.0) can't synthesize speech when the checkout path contains a space, for example under ~/Library/Application Support/.... espeak-ng ignores the bundled data directory and falls back to a hard-coded build path, /Users/runner/work/piper1-gpl/.../espeak-ng-data/phontab, so the output WAV is empty. Moving the checkout to a path without spaces fixes it. Raising it here in case it's worth a note in the setup docs.

🤖 Generated with Claude Code

Pasting the Pexels key into .env by hand is error-prone: with a non-English
keyboard layout active, a typed value can land in .env as non-ASCII text,
which later crashes stock searches with a latin-1 header encoding error.

scripts/set_pexels_key.sh prompts for the key with hidden input, rejects
anything that isn't a plain alphanumeric key, and writes it to .env.
.env.example points to the script next to PEXELS_API_KEY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yoyo8080y
yoyo8080y requested a review from calesthio as a code owner November 20, 2026 16:21
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