A comprehensive Python application for generating unique QR codes and sending them via email for event management. This system integrates with Google Sheets to manage participant data and automates the process of creating personalized QR codes for event attendees.
- Overview
- Features
- Project Structure
- Prerequisites
- Installation
- Configuration
- Usage
- Scripts Documentation
- File Structure
- Environment Variables
- Troubleshooting
This QR Code Generator system is designed for event organizers who need to:
- Generate unique identifiers for event participants
- Create QR codes for each participant
- Send personalized emails with QR codes and event information
- Track email delivery status
The system uses Google Sheets as a database to store participant information and integrates with email services to automate communication.
- π― Terminal Interface: User-friendly command-line interface for easy navigation
- π Google Sheets Integration: Seamlessly connects with Google Sheets for data management
- π Unique ID Generation: Creates UUID-based unique identifiers for each participant
- π± QR Code Generation: Generates high-quality QR codes with customizable settings
- π§ Email Automation: Sends personalized HTML emails with embedded QR codes
- β‘ Batch Processing: Handles multiple participants efficiently
- π Status Tracking: Tracks email delivery status to prevent duplicates
- π‘οΈ Error Handling: Comprehensive error handling and logging
- π¨ Customizable Templates: Uses HTML templates for professional email formatting
qr-code-gen/
βββ main.py # Terminal interface (recommended entry point)
βββ generate_uniqueId.py # Script to generate unique IDs in Google Sheets
βββ generate_QR.py # Script to generate QR codes from unique IDs
βββ send_email_with_QR.py # Script to send emails with QR codes
βββ setup.py # Automated setup script
βββ requirements.txt # Python package dependencies
βββ email_template.html # HTML template for email content
βββ env.example # Environment configuration template
βββ credentials.json # Google Service Account credentials (not tracked)
βββ .env.local # Environment variables (not tracked)
βββ .gitignore # Git ignore file
βββ qr_codes/ # Directory containing generated QR codes
βββ event-logo.png # Event logo
βββ event-schedule.pdf # Event schedule PDF
βββ README.md # This documentation file
Before you begin, ensure you have the following installed:
- Python 3.7 or higher
- pip (Python package installer)
- A Google Cloud Platform account
- A Gmail account for sending emails
git clone https://github.com/yourusername/qr-code-gen.git
cd qr-code-genUsing the requirements file (recommended):
pip install -r requirements.txtRun the automated setup script:
python setup.pyThis will automatically:
- Check Python version compatibility
- Install all required packages from
requirements.txt - Create necessary directories
- Set up environment configuration from template
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Sheets API and Google Drive API
- Create a service account:
- Go to IAM & Admin > Service Accounts
- Click "Create Service Account"
- Fill in the details and create
- Download the JSON key file and rename it to
credentials.json - Place it in the project root directory
- Create a new Google Sheet with the following columns:
name: Participant's nameemail: Participant's email addressunique_id: Will be generated automaticallyemail_sent: Will be updated automatically
- Share the sheet with the service account email (found in
credentials.json) - Note the sheet name and worksheet name for configuration
Copy the example environment file and configure it:
cp env.example .env.localEdit .env.local with your actual values:
# Google Sheets Configuration
SPREADSHEET_NAME=Event Participants Database
SHEET_NAME=Sheet1
# Email Configuration
SENDER_EMAIL=your-email@gmail.com
SENDER_PASSWORD=your-gmail-app-password
# File Paths
QR_CODES_DIR=qr_codes
PDF_ATTACHMENT_PATH=event-schedule.pdf
EMAIL_TEMPLATE_PATH=email_template.html
EMAIL_SUBJECT=Event Confirmation - QR Code Attached- Enable 2-factor authentication on your Gmail account
- Generate an App Password:
- Go to Google Account settings
- Security > 2-Step Verification > App passwords
- Generate a new app password
- Use this password in the
.env.localfile
Edit the following variables in each script if needed:
generate_uniqueId.py and generate_QR.py:
SPREADSHEET_NAME = "Event Participants Database"
SHEET_NAME = "Sheet1"Run the interactive terminal interface for the best user experience:
python main.pyThe terminal interface provides:
Main Menu Options:
- Generate Unique IDs - Add unique identifiers to your Google Sheet
- Generate QR Codes - Create QR code images from unique IDs
- Send Emails with QR Codes - Send personalized emails to participants
- Run Complete Workflow - Execute all steps in sequence
- Check Configuration - Verify system setup and requirements
- View Project Status - Display statistics and file information
Features:
- π Configuration Checking: Validates all prerequisites before execution
β οΈ Safety Confirmations: Multiple confirmations for email sending- π Progress Tracking: Real-time status updates during operations
- π‘οΈ Error Handling: Comprehensive error detection and reporting
- π Statistics Display: View QR code counts and file information
If you prefer to run scripts individually:
python generate_uniqueId.pyWhat it does:
- Connects to your Google Sheet
- Checks if a
unique_idcolumn exists, creates it if not - Generates UUID4-based unique identifiers for each participant
- Updates the sheet with the new unique IDs
python generate_QR.pyWhat it does:
- Reads unique IDs from the Google Sheet
- Generates QR codes containing the unique ID data
- Saves QR codes as PNG images in the
qr_codes/directory - Names files using the first 8 characters of the UUID
python send_email_with_QR.pyWhat it does:
- Reads participant data from Google Sheet
- Checks email sending status to avoid duplicates
- Sends HTML emails with embedded QR codes and PDF attachments
- Updates the sheet with email delivery status
Purpose: Interactive terminal interface for managing the entire QR code generation workflow.
Key Features:
- User-friendly menu system with numbered options
- Comprehensive configuration checking before each operation
- Safety confirmations for email sending operations
- Real-time progress tracking and status updates
- Complete workflow automation option
- Project statistics and file information display
Usage:
python main.pyMenu Navigation:
- Use number keys (0-6) to select options
- Follow on-screen prompts and confirmations
- Press Enter to continue after operations complete
Purpose: Generates unique UUID4-based identifiers for each participant in the Google Sheet.
Key Functions:
authenticate_google_sheets(): Establishes connection with Google Sheets APIcreate_unique_id(): Generates a UUID4 stringadd_unique_ids_to_sheet(): Main function that processes the sheet and adds unique IDs
Configuration Options:
SPREADSHEET_NAME: Name of your Google SheetSHEET_NAME: Name of the specific worksheetCREDENTIALS_FILE: Path to Google service account credentials
Purpose: Creates QR codes from the unique IDs stored in the Google Sheet.
Key Functions:
authenticate_google_sheets(): Google Sheets authenticationcreate_output_directory(): Creates the output directory for QR codesgenerate_qr_code(data, filename): Creates individual QR code imagesgenerate_qr_codes_from_sheet(): Main processing function
QR Code Settings:
- Version: 1 (automatic sizing)
- Error correction: Medium level
- Box size: 10 pixels per box
- Border: 2 boxes
- Colors: Black on white background
Output:
- PNG images saved in
qr_codes/directory - Filename format:
qr_{first_8_chars_of_uuid}.png
Purpose: Sends personalized emails with QR codes and event information to participants.
Key Functions:
authenticate_google_sheets(): Google Sheets connectionload_email_template(name): Loads and personalizes HTML email templatesend_email_with_qr_and_pdf(): Sends individual emails with attachmentssend_emails_with_qr_codes(): Main batch processing function
Email Features:
- HTML formatted emails using template
- Embedded QR code images
- PDF attachment (event schedule)
- Personalized content with participant names
- Professional email signature
- credentials.json: Google Service Account credentials (keep secure, not in version control)
- .env.local: Environment variables (not in version control)
- email_template.html: HTML template for email formatting
- requirements.txt: Python package dependencies
- qr_codes/: Directory containing all generated QR code images
- Individual QR files: Named as
qr_{uuid_prefix}.png
- event-logo.png: Event logo for branding
- event-schedule.pdf: Event schedule attached to emails
| Variable | Description | Example |
|---|---|---|
SPREADSHEET_NAME |
Name of your Google Sheet | "Event Participants Database" |
SHEET_NAME |
Worksheet name | "Sheet1" |
SENDER_EMAIL |
Gmail address for sending emails | "event@gmail.com" |
SENDER_PASSWORD |
Gmail app password | "abcd efgh ijkl mnop" |
QR_CODES_DIR |
Directory for QR codes | "qr_codes" |
PDF_ATTACHMENT_PATH |
Path to PDF attachment | "event-schedule.pdf" |
EMAIL_TEMPLATE_PATH |
Path to email template | "email_template.html" |
EMAIL_SUBJECT |
Email subject line | "Event Confirmation - QR Code Attached" |
-
Authentication Error
Error: [Errno 2] No such file or directory: 'credentials.json'Solution: Ensure
credentials.jsonis in the project root directory. -
Spreadsheet Not Found
Error: Spreadsheet 'Event Participants Database' not found.Solution: Check the spreadsheet name and ensure the service account has access.
-
Email Authentication Failed
Error: (535, b'5.7.8 Username and Password not accepted')Solution: Use Gmail App Password instead of regular password.
-
QR Code Directory Missing
Warning: QR code image not foundSolution: Run
Generate QR Codesoption before sending emails. -
Module Import Error
ModuleNotFoundError: No module named 'qrcode'Solution: Install dependencies with
pip install -r requirements.txt
The terminal interface includes a "Check Configuration" option that will:
- Verify Python version compatibility
- Check for all required files
- Validate Python package installations
- Display directory and file status
- Provide specific guidance for fixing issues
- Use the terminal interface's configuration check feature
- Ensure all required columns exist in your Google Sheet
- Verify that the service account email has editor access to the sheet
- Check that the PDF attachment file exists
- Verify internet connectivity for API calls
Getting Started Quickly:
-
Clone the repository and install dependencies:
git clone <repository-url> cd qr-code-gen pip install -r requirements.txt
-
Set up your Google credentials and configuration files
-
Run the terminal interface:
python main.py
-
Use the "Check Configuration" option to verify everything is set up correctly
-
Follow the workflow: Generate IDs β Generate QR Codes β Send Emails
For detailed setup instructions, see the Installation and Configuration sections above.