Skip to main content

The easy command line QR code generator

Project description

EZQRCLI

The easy QR code command-line interface

Overview

EZQRCLI is a command-line tool for generating and displaying QR codes in the terminal. It allows you to encode URLs into QR codes and display them with optional text above and below the QR code.

Installation

To install EZQRCLI, you need to have Python 3.10 or higher. You can install the required dependencies using pip:

pip install ezqrcli

Usage

You can use EZQRCLI from the command line to generate and display QR codes. Below are the available command-line options:

usage: ezqrcli [-h] [-t TOP_TEXT] [-b BOTTOM_TEXT] [-w CENTER_WEIGHT] url

Generate and display a QR code in the terminal with optional text.

positional arguments:
  url                   The URL to encode in the QR code.

optional arguments:
  -h, --help            show this help message and exit
  -t TOP_TEXT, --top-text TOP_TEXT
                        Text to display above the QR code. Defaults to "Scan this QR code:".
  -b BOTTOM_TEXT, --bottom-text BOTTOM_TEXT
                        Text to display below the QR code. Defaults to the URL, truncated to 50 chars.
  -w CENTER_WEIGHT, --center-weight CENTER_WEIGHT
                        Weight to adjust the centering of the QR code. Default is 1.0.

Example usage:

python -m ezqrcli "https://example.com" -t "Welcome!" -b "Scan to visit example.com"

Code Structure

QRCLI Class

The QRCLI class is responsible for generating and displaying QR codes in the terminal. It has the following attributes and methods:

Attributes

  • url (str): The URL to encode in the QR code.
  • top_text (str): Text to display above the QR code. Default is "Scan this QR code:".
  • bottom_text (str): Text to display below the QR code. Defaults to the first 50 chars of the URL.
  • center_weight (float): Weight to adjust the centering of the QR code. Default is 1.0.
  • maxwidth (int): Maximum width of the QR code.
  • _raw_qr (str): Raw QR code data.
  • qr_text (str): Processed QR code text.
  • formatted_qr (str): Formatted QR code with padding and text.
  • padding (str): Padding to center the QR code vertically.
  • width (int): Width of the terminal.
  • height (int): Height of the terminal.
  • centered_qr_text (str): Centered QR code text.
  • _raw_lines (list): List of raw QR code lines.
  • qrcode (module): QR code module.

Methods

  • ensure_qrcode(): Static method to install the qrcode module.
  • _ensure_qrcode(): Attempts to import the qrcode module, installs it if not found.
  • _update(): Updates the QR code and its attributes.
  • _get_padding() -> str: Calculates the padding to center the QR code vertically.
  • _get_width() -> int: Calculates the width of the terminal.
  • _get_height() -> int: Calculates the height of the terminal.
  • _generate_qr(): Generates the QR code from the URL.
  • _process_qr(): Processes the raw QR code to center its lines.
  • _center_qr() -> str: Centers the QR code text and adds top and bottom text.
  • _format_qr(): Formats the QR code with padding and text.
  • get_formatted_qr() -> str: Returns the formatted QR code.
  • get_raw_qr() -> str: Returns the raw QR code.
  • display_qr(): Displays the formatted QR code in the terminal.

ensure_qrcode Function

The ensure_qrcode function in ezqrcli/util.py ensures that the qrcode package is installed and available for import. If the module is not found, it installs it using pip.

Testing

To run the tests, use the following command:

pytest

The tests are located in the tests directory and cover various aspects of the QRCLI class.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezqrcli-1.0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

ezqrcli-1.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ezqrcli-1.0.1.tar.gz.

File metadata

  • Download URL: ezqrcli-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Windows/11

File hashes

Hashes for ezqrcli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f38b6d0ebbee791be1afc32d6f7a3c5a42cc38de34cd91994ea5fdf95df394cf
MD5 40e88365dc4c6e4eaa4550ef370d5d3d
BLAKE2b-256 a7d3035a606583520355a83bd71c20f6c3bae7c2d264f317f5e99928038ca736

See more details on using hashes here.

File details

Details for the file ezqrcli-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ezqrcli-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Windows/11

File hashes

Hashes for ezqrcli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d730804dd9097c2e99af5b4efe31884fb2000ff754e7bd7d7c1db109676b1ab
MD5 335627fa847a7c648e0fbefab854fee2
BLAKE2b-256 d988610215d79df76b455a7f9268076074375686d5011a144b8c05d606c4f90e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page