vincentiusyoshuac commited on
Commit
d1460a1
1 Parent(s): af70447

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +173 -0
app.py ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import qrcode
2
+ from qrcode.constants import ERROR_CORRECT_L
3
+ import streamlit as st
4
+ from datetime import datetime
5
+ from urllib.parse import urlencode
6
+
7
+ def generate_contact_qr(contact_info):
8
+ """
9
+ Generates a QR code for contact information in the vCard format.
10
+
11
+ Parameters:
12
+ contact_info (dict): A dictionary containing the contact information fields.
13
+
14
+ Returns:
15
+ PIL.Image.Image: The generated QR code image.
16
+ """
17
+ vcard = "BEGIN:VCARD\n"
18
+ vcard += f"VERSION:4.0\n"
19
+ vcard += f"N:{contact_info['last_name']};{contact_info['first_name']}\n"
20
+ vcard += f"EMAIL:{contact_info['email']}\n"
21
+ vcard += f"TEL:{contact_info['phone']}\n"
22
+ vcard += f"ORG:{contact_info['organization']}\n"
23
+ vcard += f"TITLE:{contact_info['job_title']}\n"
24
+ vcard += "END:VCARD"
25
+
26
+ qr = qrcode.QRCode(
27
+ version=1,
28
+ error_correction=ERROR_CORRECT_L,
29
+ box_size=10,
30
+ border=4,
31
+ )
32
+ qr.add_data(vcard)
33
+ qr.make(fit=True)
34
+ return qr.make_image(fill_color="black", back_color="white")
35
+
36
+ def generate_email_qr(email_info):
37
+ """
38
+ Generates a QR code for an email.
39
+
40
+ Parameters:
41
+ email_info (dict): A dictionary containing the email information fields.
42
+
43
+ Returns:
44
+ PIL.Image.Image: The generated QR code image.
45
+ """
46
+ email_url = f"mailto:{email_info['to']}?subject={email_info['subject']}&body={email_info['body']}"
47
+ qr = qrcode.QRCode(
48
+ version=1,
49
+ error_correction=ERROR_CORRECT_L,
50
+ box_size=10,
51
+ border=4,
52
+ )
53
+ qr.add_data(email_url)
54
+ qr.make(fit=True)
55
+ return qr.make_image(fill_color="black", back_color="white")
56
+
57
+ def generate_sms_qr(sms_info):
58
+ """
59
+ Generates a QR code for an SMS message.
60
+
61
+ Parameters:
62
+ sms_info (dict): A dictionary containing the SMS information fields.
63
+
64
+ Returns:
65
+ PIL.Image.Image: The generated QR code image.
66
+ """
67
+ sms_url = f"sms:{sms_info['to']}?body={sms_info['body']}"
68
+ qr = qrcode.QRCode(
69
+ version=1,
70
+ error_correction=ERROR_CORRECT_L,
71
+ box_size=10,
72
+ border=4,
73
+ )
74
+ qr.add_data(sms_url)
75
+ qr.make(fit=True)
76
+ return qr.make_image(fill_color="black", back_color="white")
77
+
78
+ def generate_location_qr(latitude, longitude):
79
+ """
80
+ Generates a QR code for a geographic location.
81
+
82
+ Parameters:
83
+ latitude (float): The latitude of the location.
84
+ longitude (float): The longitude of the location.
85
+
86
+ Returns:
87
+ PIL.Image.Image: The generated QR code image.
88
+ """
89
+ location_url = f"https://www.google.com/maps?q={latitude},{longitude}"
90
+ qr = qrcode.QRCode(
91
+ version=1,
92
+ error_correction=ERROR_CORRECT_L,
93
+ box_size=10,
94
+ border=4,
95
+ )
96
+ qr.add_data(location_url)
97
+ qr.make(fit=True)
98
+ return qr.make_image(fill_color="black", back_color="white")
99
+
100
+ def generate_link_qr(url):
101
+ """
102
+ Generates a QR code for a URL.
103
+
104
+ Parameters:
105
+ url (str): The URL to be encoded.
106
+
107
+ Returns:
108
+ PIL.Image.Image: The generated QR code image.
109
+ """
110
+ qr = qrcode.QRCode(
111
+ version=1,
112
+ error_correction=ERROR_CORRECT_L,
113
+ box_size=10,
114
+ border=4,
115
+ )
116
+ qr.add_data(url)
117
+ qr.make(fit=True)
118
+ return qr.make_image(fill_color="black", back_color="white")
119
+
120
+ def main():
121
+ st.set_page_config(page_title="Advanced QR Code Generator")
122
+ st.title("Advanced QR Code Generator")
123
+
124
+ tab = st.sidebar.selectbox("Select QR Code Type", ["Contact", "Email", "SMS", "Location", "Link"])
125
+
126
+ if tab == "Contact":
127
+ st.subheader("Contact QR Code")
128
+ contact_info = {
129
+ "first_name": st.text_input("First Name"),
130
+ "last_name": st.text_input("Last Name"),
131
+ "email": st.text_input("Email"),
132
+ "phone": st.text_input("Phone"),
133
+ "organization": st.text_input("Organization"),
134
+ "job_title": st.text_input("Job Title"),
135
+ }
136
+ if st.button("Generate QR Code"):
137
+ qr_code = generate_contact_qr(contact_info)
138
+ st.image(qr_code, use_column_width=True)
139
+ elif tab == "Email":
140
+ st.subheader("Email QR Code")
141
+ email_info = {
142
+ "to": st.text_input("To"),
143
+ "subject": st.text_input("Subject"),
144
+ "body": st.text_area("Body"),
145
+ }
146
+ if st.button("Generate QR Code"):
147
+ qr_code = generate_email_qr(email_info)
148
+ st.image(qr_code, use_column_width=True)
149
+ elif tab == "SMS":
150
+ st.subheader("SMS QR Code")
151
+ sms_info = {
152
+ "to": st.text_input("To"),
153
+ "body": st.text_area("Message"),
154
+ }
155
+ if st.button("Generate QR Code"):
156
+ qr_code = generate_sms_qr(sms_info)
157
+ st.image(qr_code, use_column_width=True)
158
+ elif tab == "Location":
159
+ st.subheader("Location QR Code")
160
+ latitude = st.number_input("Latitude", min_value=-90.0, max_value=90.0, step=0.000001)
161
+ longitude = st.number_input("Longitude", min_value=-180.0, max_value=180.0, step=0.000001)
162
+ if st.button("Generate QR Code"):
163
+ qr_code = generate_location_qr(latitude, longitude)
164
+ st.image(qr_code, use_column_width=True)
165
+ elif tab == "Link":
166
+ st.subheader("Link QR Code")
167
+ url = st.text_input("URL")
168
+ if st.button("Generate QR Code"):
169
+ qr_code = generate_link_qr(url)
170
+ st.image(qr_code, use_column_width=True)
171
+
172
+ if __name__ == "__main__":
173
+ main()