Skip to content

Instantly share code, notes, and snippets.

@pilotmoon
Last active March 26, 2025 07:58
Show Gist options
  • Save pilotmoon/ce93a0412a8db6cf6ffaa365042128e8 to your computer and use it in GitHub Desktop.
Save pilotmoon/ce93a0412a8db6cf6ffaa365042128e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# #popclip
# name: ESV Copy
# identifier: com.example.popclip.esvcopy
# after: copy-result
# regex: '^(?:[1-3]\s+)?[A-Za-z]+\s+\d+:\d+(?:[-–—]\d+)?$'
# esv_lookup.py – Fetch Bible passage text from the ESV API and output to stdout.
import os
import json
from urllib import request, parse
# **Configuration**: ESV API credentials and endpoint
API_KEY = "YOUR API KEY HERE" # ESV API key (replace with your own if needed)
API_URL = "https://api.esv.org/v3/passage/text/" # ESV Passage Text API endpoint
# (For other translations, use their API URL and key here. E.g., update API_URL for a different service)
# Get the Bible reference from the PopClip selection
reference = os.environ.get("POPCLIP_TEXT", "").strip()
# Prepare query parameters for the API request to minimize clutter in the output
params = {
"q": reference,
"include-footnotes": "false", # omit footnote call markers for cleaner text
"include-footnote-body": "false", # do not include footnote text at the bottom
"include-headings": "false" # omit section headings to focus only on verses
# (By default, verse numbers and passage reference are included as True, which we want)
# You can add or adjust parameters here for formatting tweaks.
# For example, to exclude verse numbers, set "include-verse-numbers": "false"
}
query_string = parse.urlencode(params)
# Make the HTTP request to the ESV API
req = request.Request(f"{API_URL}?{query_string}")
req.add_header("Authorization", f"Token {API_KEY}") # supply API key in the header
with request.urlopen(req) as resp:
data = json.load(resp)
# Extract the passage text from the JSON response
passages = data.get("passages", [])
if passages:
text = passages[0].strip()
else:
text = "Error: Verse text not found."
# Output the passage text to stdout (PopClip will capture this and copy it)
print(text, end="")
@pilotmoon
Copy link
Author

pilotmoon commented Mar 26, 2025

(The above block is an extension snippet — select it then click "Install Extension" in PopClip.)

Reference: https://forum.popclip.app/t/extension-not-showing-with-regex-hyphen-vs-en-em-dash/3248/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment