From 421b5c580242accc016b998ba5496c797d6924a7 Mon Sep 17 00:00:00 2001 From: Luckman Date: Sat, 4 Oct 2025 13:56:41 +0530 Subject: [PATCH] refactor(qr): Improve QR code generator script --- qr.py | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/qr.py b/qr.py index b097afbd..83e1defe 100644 --- a/qr.py +++ b/qr.py @@ -1,11 +1,36 @@ -import pyqrcode -from pyqrcode import QRCode - -# String which represent the QR code -s = "https://fueler.io/arjun_ms" - -# Generate QR code -url = pyqrcode.create(s) - -# Create and save the png file naming "myqr.png" -url.svg("myyoutube.svg", scale = 8) \ No newline at end of file +# Before running, install the required library: pip install qrcode + +import qrcode +from pathlib import Path +from datetime import datetime + +# Data to encode in the QR code (e.g., a website link, text, etc.) +data_to_encode = "Information you want QR code to store" + +# Create a unique filename using the current timestamp +timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") +filename = f"qr_{timestamp}.png" + + +# This creates a path to C:\Users\YourName\Downloads\qr_...png (on Windows) +downloads_dir = Path.home() / "Downloads" +# Ensure the Downloads directory exists before saving +downloads_dir.mkdir(exist_ok=True) +save_path = downloads_dir / filename + +# Generate the QR code object +qr = qrcode.QRCode( + version=1, + box_size=10, + border=5, +) +qr.add_data(data_to_encode) +qr.make(fit=True) + +# Create an image from the QR code object +img = qr.make_image(fill_color="black", back_color="white") + +# Save the image file +img.save(save_path) + +print(f"QR Code saved successfully to your Downloads folder: {save_path}")