feat: QR PNG 생성 + vote URL resolver

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
th-kim0823
2026-04-27 19:54:31 +09:00
parent 546bd54700
commit 874de0a46d
2 changed files with 66 additions and 0 deletions

32
app.py
View File

@@ -11,8 +11,11 @@ import os
import random as _rand
import threading
from datetime import datetime
import socket
from io import BytesIO
from pathlib import Path
import qrcode
import streamlit as st
DATA_PATH = os.environ.get(
@@ -200,6 +203,35 @@ def fmt_team(team, titles):
return f"{team}{t}" if t else team
def make_qr_png(url: str, box_size: int = 20) -> bytes:
img = qrcode.make(url, box_size=box_size, border=2)
buf = BytesIO()
img.save(buf, format="PNG")
return buf.getvalue()
def _detect_lan_ip() -> str:
"""LAN IP 자동 감지. 실패 시 'localhost'."""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
except Exception:
return "localhost"
def compute_vote_url() -> str:
data = load_data()
base = (
data.get("settings", {}).get("public_base_url")
or os.environ.get("PUBLIC_BASE_URL")
or f"http://{_detect_lan_ip()}:8501"
)
return f"{base.rstrip('/')}/?mode=vote"
def compute_winners():
"""우선순위 기반 1팀 1상 + 동률 처리."""
data = load_data()