This project provides a Python script to generate QR codes from various types of data such as URLs, email addresses, SMS messages, phone numbers, and plain text. The generated QR code can be saved in either PNG or PDF format.
segnoargparsesys
You can install the segno library using pip:
pip install segnoThe script can be executed from the command line. Below are the available options and their usage:
python basic_qrcode.py [-h] [-t {url,email,sms,call,text}] [-d DATA] [-o OUTPUT] [-f {png,pdf}]-t,--type: The type of data to encode. Choices areurl,email,sms,call, andtext.-d,--data: The data to encode in the QR code.-o,--output: The output filename (without extension).-f,--format: The format/extension of the output file. Choices arepng,pdf. The default ispng.-h,--help: Show help message. Optionally, provide a data type for more specific help.
Each data type has specific formatting requirements:
-
URL:
- Expects a valid URL.
- Example:
-d 'http://example.com'.
-
Email:
- Expects data in the format
<email-address><subject><body>. - Example:
-d '<someone@example.com><Subject><Body>'.
- Expects data in the format
-
SMS:
- Expects data in the format
<phone-number><message>. - Example:
-d '<1234567890><Hello, this is a message>'.
- Expects data in the format
-
Call:
- Expects a phone number.
- Example:
-d '1234567890'.
-
Text:
- Expects plain text.
- Example:
-d 'This is a plain text message.'.
-
Create a QR code for a URL:
python basic_qrcode.py -t url -d 'http://example.com' -o my_qr_code -f pngThis will create a QR code for
http://example.comand save it asmy_qr_code.png. -
Create a QR code for an email:
python basic_qrcode.py -t email -d '<someone@example.com><Hello><This is the body>' -o my_email_qr_code -f pngThis will create a QR code for the email and save it as
my_email_qr_code.png. -
Create a QR code for an SMS:
python basic_qrcode.py -t sms -d '<1234567890><Hello there>' -o my_sms_qr_code -f pdfThis will create a QR code for the SMS and save it as
my_sms_qr_code.pdf.
In case of invalid input, the script will display an appropriate error message and provide guidance on the expected format for the specified data type.
To get detailed help for a specific data type, you can use the -h or --help flag followed by the data type:
python basic_qrcode.py -h urlThis will provide more specific information about the expected format for the URL data type.
This project is licensed under the MIT License.
- Developed using the
segnolibrary for generating QR codes.