File size: 2,926 Bytes
ba30490
 
 
 
b65111f
ba30490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import streamlit as st
import qrcode
from unidecode import unidecode
from PIL import Image

import io





#inputs
name = st.text_input("Ad", key="name")
last_name = st.text_input("Soyad", key="last_name")
title = st.text_input("Ünvan", key="title")
e_mail = st.text_input("E-posta adresi", key="email")
e_mail2 = st.text_input("E-posta adresi2", key="email2")
tel = st.text_input("Telefon", key="tel")
mobile = st.text_input("Mobil Telefon", key="mobile")
home_address = st.text_input("Ev adresi", key="home_address")
work_address = st.text_input("İş adresi", key="work_address")
organisation = st.text_input("İşyeri Adı", key="organisation")
website = st.text_input("Websitesi", key="website")

def generate_qr_code(data):
    # Create the vCard text as a string
    vcard_template = """BEGIN:VCARD;CHARSET=iso-8859-1
    VERSION:4.0
    N:{last_name};{name}
    FN:{name} {last_name}
    ORG:{organisation}
    TITLE: {title}
    EMAIL;PREF=1;TYPE=INTERNET:{email}
    EMAIL:{email2}
    TEL;TYPE#work,voice;VALUE#uri:tel:{tel}
    TEL;TYPE#mobile,voice;VALUE#uri:tel:{mobile}
    ADR;TYPE#WORK;PREF#1: {work_address}
    ADR;TYPE#HOME: {home_address}
    URL:{website}
    END:VCARD"""

    # Format the vCard text with the variables from the data dictionary
    vcard_text = vcard_template.format(**data)

    # Create the QR code image
    qr_img = qrcode.make(vcard_text, box_size=10)

    # Convert the QR code image to a bytes-like object
    img_bytes = io.BytesIO()
    qr_img.save(img_bytes, format='PNG')
    img_bytes.seek(0)

    # Create the PIL Image object
    pil_img = Image.open(img_bytes)

    return pil_img


# Add a "Generate QR Code" button
if st.button("Dijital Kartvizit Oluşturun"):
    # Create the data dictionary
    data = {
        "name": name,
        "last_name": last_name,
        "email": e_mail,
        "email2": e_mail2,
        "tel": tel,
        "mobile": mobile,
        "home_address": home_address,
        "work_address": work_address,
        "organisation": organisation,
        "website": website,
        "title": title
    }
    # Generate the QR code image
    img = generate_qr_code(data)
    # Display the QR code image
    st.image(img)
    
    # Convert the image to bytes
    img_bytes = io.BytesIO()
    img.save(img_bytes, format='PNG')
    # Add a download button for the image
    st.download_button(
        label=" ⬇️ VR Kodunu İndirin",
        data=img_bytes.getvalue(),
        file_name="qrcode.png",
        mime="image/png"
    )

# Convert the name to Latin characters using the unidecode function
file_name = unidecode(name)

# Make the file name all lowercase
file_name = file_name.lower()

# Replace any spaces with underscores
file_name = file_name.replace(' ', '_')

# Add the .png extension to the file name
file_name = f'{file_name}_vcard.png'

# Save the QR code image to a file
#with open(file_name, 'wb') as f:
    #img.save(f)