Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Logging and Add URL to QR Code Filename #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions QR_code_generator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import qrcode

# Enter url of any website here.
input_URL = "https://www.google.com/"

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=15,
border=4,
)

qr.add_data(input_URL)
qr.make(fit=True)

# convert into image
img = qr.make_image(fill_color="red", back_color="white")
img.save("url_qrcode.png")

print(qr.data_list)
import qrcode
import logging

# Set up basic logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

# Enter url of any website here.
input_URL = "https://www.google.com/"

# Sanitize the URL to include in the filename
sanitized_url = input_URL.replace('https://', '').replace('http://', '').replace('/', '_').replace('.', '_')

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=15,
border=4,
)

try:
logging.info('Starting QR code generation.')
qr.add_data(input_URL)
qr.make(fit=True)

# convert into image
img = qr.make_image(fill_color="red", back_color="white")
filename = f"{sanitized_url}_qrcode.png"
img.save(filename)
logging.info(f'QR code image saved as {filename}')
except Exception as e:
logging.error(f'An error occurred during QR code generation or saving: {e}')

print(qr.data_list)