-
Notifications
You must be signed in to change notification settings - Fork 0
/
py_qrcode.py
37 lines (31 loc) · 975 Bytes
/
py_qrcode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import qrcode
import uuid
def generate_random_name():
# Generate a UUID
unique_id = uuid.uuid4()
# Convert the UUID to a string and remove hyphens
name = str(unique_id).replace('-', '')
return name
def generate_qr(data: str):
loop = True
while loop:
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
name = generate_random_name()
img.save(f"{name}.png")
print(f"Successfully printed {name}.png")
question = input("Print another one? (Enter Y/N): ")
if question.upper() == "N":
loop = False
try:
data = input("Enter a website or code: ")
generate_qr(data)
except Exception as e:
print(f"Error: {e}")