Skip to content

Commit

Permalink
generate the QR codes directly instead of using an API
Browse files Browse the repository at this point in the history
  • Loading branch information
hwalker928 committed Dec 13, 2024
1 parent e81f159 commit eaa57be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import logging
import os
import datetime
import qrcode
import io
import base64

# Configure logging
logging.basicConfig(
Expand Down Expand Up @@ -57,10 +60,17 @@ def qrcodes():

for person in people:
person_base64_reversed = person.encode("utf-8").hex()[::-1]

qr = qrcode.make(f"{config['url']}/qrscan/{person_base64_reversed}")
buffer = io.BytesIO()
qr.save(buffer, format="PNG")
qr_img_bytes = base64.b64encode(buffer.getvalue()).decode()
buffer.close()

people_dict.append(
{
"name": person.capitalize(),
"qr": f"https://api.qrserver.com/v1/create-qr-code/?data={config['url']}/qrscan/{person_base64_reversed}&size=200x200",
"qr": qr_img_bytes,
}
)

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
redis
redis
qrcode
7 changes: 6 additions & 1 deletion templates/qrcodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ <h2>QR Codes [{% if active %}Active{% else %}Inactive{% endif %}]</h2>
{% for person in people_dict %}
<tr>
<td>{{ person["name"] }}</td>
<td><img src="{{ person['qr'] }}" alt="{{ person['name'] }}" /></td>
<td>
<img
src="data:image/png;base64,{{ person['qr'] }}"
alt="{{ person['name'] }}"
/>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit eaa57be

Please sign in to comment.