Skip to content

Instantly share code, notes, and snippets.

@bradmartin333
Created June 6, 2025 19:26
Show Gist options
  • Save bradmartin333/1a8d96d9d7ea62aad4afe5df8fcd395e to your computer and use it in GitHub Desktop.
Save bradmartin333/1a8d96d9d7ea62aad4afe5df8fcd395e to your computer and use it in GitHub Desktop.
print zen quote to USB thermal printer
import requests
PRINTER_DEVICE = "/dev/usb/lp0"
with open(PRINTER_DEVICE, "wb") as printer:
response = requests.get("https://zenquotes.io/api/random")
response.raise_for_status()
data = response.json()
if data and isinstance(data, list) and len(data) > 0:
quote_data = data[0]
quote = quote_data.get("q")
author = quote_data.get("a")
if quote and author:
formatted_quote = f'"{quote}"\n- {author}\n\n\n\n'
printer.write(formatted_quote.encode("utf-8"))
printer.write(b"\x0c")
print(f"successfully printed to {PRINTER_DEVICE}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment